library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
  method         from
  print.tbl_lazy     
  print.tbl_sql      
── Attaching packages ──────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.3.6     ✔ purrr   0.3.4
✔ tibble  3.1.7     ✔ dplyr   1.0.9
✔ tidyr   1.2.0     ✔ stringr 1.4.0
✔ readr   2.1.2     ✔ forcats 0.5.1
── Conflicts ─────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(modelr)
library(skimr)
library(GGally)
Registered S3 method overwritten by 'GGally':
  method from   
  +.gg   ggplot2

###cleaning for regression

kc_houses <- read_csv("data/kc_house_data.csv")
Rows: 21613 Columns: 21
── Column specification ─────────────────────────────────────────────────────────
Delimiter: ","
chr   (1): id
dbl  (19): price, bedrooms, bathrooms, sqft_living, sqft_lot, floors, waterfr...
dttm  (1): date

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

###removing aliases

alias(lm(price ~ ., data = kc_houses))
Model :
price ~ bedrooms + bathrooms + sqft_living + sqft_lot + floors + 
    waterfront + view + condition + grade + yr_built + yr_renovated + 
    lat + long + sqft_living15 + sqft_lot15

###choosing first predictor for model

ggpairs(kc_houses_numeric)

 plot: [1,1] [-------------------------------------------------]  1% est: 0s 
 plot: [1,2] [>------------------------------------------------]  2% est: 7s 
 plot: [1,3] [>------------------------------------------------]  2% est: 8s 
 plot: [1,4] [=>-----------------------------------------------]  3% est: 9s 
 plot: [1,5] [=>-----------------------------------------------]  4% est: 9s 
 plot: [1,6] [=>-----------------------------------------------]  5% est: 9s 
 plot: [1,7] [==>----------------------------------------------]  6% est: 9s 
 plot: [1,8] [==>----------------------------------------------]  7% est: 9s 
 plot: [1,9] [===>---------------------------------------------]  7% est: 8s 
 plot: [1,10] [===>--------------------------------------------]  8% est: 9s 
 plot: [1,11] [===>--------------------------------------------]  9% est: 9s 
 plot: [2,1] [====>--------------------------------------------] 10% est: 9s 
 plot: [2,2] [====>--------------------------------------------] 11% est: 9s 
 plot: [2,3] [=====>-------------------------------------------] 12% est: 9s 
 plot: [2,4] [=====>-------------------------------------------] 12% est: 9s 
 plot: [2,5] [=====>-------------------------------------------] 13% est: 9s 
 plot: [2,6] [======>------------------------------------------] 14% est: 8s 
 plot: [2,7] [======>------------------------------------------] 15% est: 8s 
 plot: [2,8] [=======>-----------------------------------------] 16% est: 8s 
 plot: [2,9] [=======>-----------------------------------------] 17% est: 8s 
 plot: [2,10] [=======>----------------------------------------] 17% est: 8s 
 plot: [2,11] [========>---------------------------------------] 18% est: 8s 
 plot: [3,1] [========>----------------------------------------] 19% est: 8s 
 plot: [3,2] [=========>---------------------------------------] 20% est: 8s 
 plot: [3,3] [=========>---------------------------------------] 21% est: 8s 
 plot: [3,4] [==========>--------------------------------------] 21% est: 8s 
 plot: [3,5] [==========>--------------------------------------] 22% est: 8s 
 plot: [3,6] [==========>--------------------------------------] 23% est: 8s 
 plot: [3,7] [===========>-------------------------------------] 24% est: 8s 
 plot: [3,8] [===========>-------------------------------------] 25% est: 7s 
 plot: [3,9] [============>------------------------------------] 26% est: 7s 
 plot: [3,10] [============>-----------------------------------] 26% est: 7s 
 plot: [3,11] [============>-----------------------------------] 27% est: 7s 
 plot: [4,1] [=============>-----------------------------------] 28% est: 7s 
 plot: [4,2] [=============>-----------------------------------] 29% est: 7s 
 plot: [4,3] [==============>----------------------------------] 30% est: 7s 
 plot: [4,4] [==============>----------------------------------] 31% est: 7s 
 plot: [4,5] [==============>----------------------------------] 31% est: 7s 
 plot: [4,6] [===============>---------------------------------] 32% est: 7s 
 plot: [4,7] [===============>---------------------------------] 33% est: 7s 
 plot: [4,8] [================>--------------------------------] 34% est: 7s 
 plot: [4,9] [================>--------------------------------] 35% est: 7s 
 plot: [4,10] [================>-------------------------------] 36% est: 6s 
 plot: [4,11] [================>-------------------------------] 36% est: 6s 
 plot: [5,1] [=================>-------------------------------] 37% est: 6s 
 plot: [5,2] [==================>------------------------------] 38% est: 6s 
 plot: [5,3] [==================>------------------------------] 39% est: 6s 
 plot: [5,4] [==================>------------------------------] 40% est: 6s 
 plot: [5,5] [===================>-----------------------------] 40% est: 6s 
 plot: [5,6] [===================>-----------------------------] 41% est: 6s 
 plot: [5,7] [====================>----------------------------] 42% est: 6s 
 plot: [5,8] [====================>----------------------------] 43% est: 6s 
 plot: [5,9] [====================>----------------------------] 44% est: 6s 
 plot: [5,10] [====================>---------------------------] 45% est: 6s 
 plot: [5,11] [=====================>--------------------------] 45% est: 6s 
 plot: [6,1] [======================>--------------------------] 46% est: 5s 
 plot: [6,2] [======================>--------------------------] 47% est: 5s 
 plot: [6,3] [======================>--------------------------] 48% est: 5s 
 plot: [6,4] [=======================>-------------------------] 49% est: 5s 
 plot: [6,5] [=======================>-------------------------] 50% est: 5s 
 plot: [6,6] [========================>------------------------] 50% est: 5s 
 plot: [6,7] [========================>------------------------] 51% est: 5s 
 plot: [6,8] [=========================>-----------------------] 52% est: 5s 
 plot: [6,9] [=========================>-----------------------] 53% est: 5s 
 plot: [6,10] [=========================>----------------------] 54% est: 5s 
 plot: [6,11] [=========================>----------------------] 55% est: 5s 
 plot: [7,1] [==========================>----------------------] 55% est: 5s 
 plot: [7,2] [===========================>---------------------] 56% est: 5s 
 plot: [7,3] [===========================>---------------------] 57% est: 5s 
 plot: [7,4] [===========================>---------------------] 58% est: 4s 
 plot: [7,5] [============================>--------------------] 59% est: 4s 
 plot: [7,6] [============================>--------------------] 60% est: 4s 
 plot: [7,7] [=============================>-------------------] 60% est: 4s 
 plot: [7,8] [=============================>-------------------] 61% est: 4s 
 plot: [7,9] [=============================>-------------------] 62% est: 4s 
 plot: [7,10] [=============================>------------------] 63% est: 4s 
 plot: [7,11] [==============================>-----------------] 64% est: 4s 
 plot: [8,1] [===============================>-----------------] 64% est: 4s 
 plot: [8,2] [===============================>-----------------] 65% est: 4s 
 plot: [8,3] [===============================>-----------------] 66% est: 4s 
 plot: [8,4] [================================>----------------] 67% est: 4s 
 plot: [8,5] [================================>----------------] 68% est: 4s 
 plot: [8,6] [=================================>---------------] 69% est: 3s 
 plot: [8,7] [=================================>---------------] 69% est: 3s 
 plot: [8,8] [=================================>---------------] 70% est: 3s 
 plot: [8,9] [==================================>--------------] 71% est: 3s 
 plot: [8,10] [==================================>-------------] 72% est: 3s 
 plot: [8,11] [==================================>-------------] 73% est: 3s 
 plot: [9,1] [===================================>-------------] 74% est: 3s 
 plot: [9,2] [===================================>-------------] 74% est: 3s 
 plot: [9,3] [====================================>------------] 75% est: 3s 
 plot: [9,4] [====================================>------------] 76% est: 3s 
 plot: [9,5] [=====================================>-----------] 77% est: 3s 
 plot: [9,6] [=====================================>-----------] 78% est: 3s 
 plot: [9,7] [=====================================>-----------] 79% est: 2s 
 plot: [9,8] [======================================>----------] 79% est: 2s 
 plot: [9,9] [======================================>----------] 80% est: 2s 
 plot: [9,10] [======================================>---------] 81% est: 2s 
 plot: [9,11] [======================================>---------] 82% est: 2s 
 plot: [10,1] [=======================================>--------] 83% est: 2s 
 plot: [10,2] [=======================================>--------] 83% est: 2s 
 plot: [10,3] [=======================================>--------] 84% est: 2s 
 plot: [10,4] [========================================>-------] 85% est: 2s 
 plot: [10,5] [========================================>-------] 86% est: 2s 
 plot: [10,6] [=========================================>------] 87% est: 2s 
 plot: [10,7] [=========================================>------] 88% est: 1s 
 plot: [10,8] [=========================================>------] 88% est: 1s 
 plot: [10,9] [==========================================>-----] 89% est: 1s 
 plot: [10,10] [=========================================>-----] 90% est: 1s 
 plot: [10,11] [==========================================>----] 91% est: 1s 
 plot: [11,1] [===========================================>----] 92% est: 1s 
 plot: [11,2] [===========================================>----] 93% est: 1s 
 plot: [11,3] [============================================>---] 93% est: 1s 
 plot: [11,4] [============================================>---] 94% est: 1s 
 plot: [11,5] [=============================================>--] 95% est: 1s 
 plot: [11,6] [=============================================>--] 96% est: 1s 
 plot: [11,7] [=============================================>--] 97% est: 0s 
 plot: [11,8] [==============================================>-] 98% est: 0s 
 plot: [11,9] [==============================================>-] 98% est: 0s 
 plot: [11,10] [==============================================>] 99% est: 0s 
 plot: [11,11] [===============================================]100% est: 0s 
                                                                             
ggsave("numeric.png", width = 20, height = 20)

 plot: [1,1] [-------------------------------------------------]  1% est: 0s 
 plot: [1,2] [>------------------------------------------------]  2% est: 5s 
 plot: [1,3] [>------------------------------------------------]  2% est: 6s 
 plot: [1,4] [=>-----------------------------------------------]  3% est: 7s 
 plot: [1,5] [=>-----------------------------------------------]  4% est: 7s 
 plot: [1,6] [=>-----------------------------------------------]  5% est: 7s 
 plot: [1,7] [==>----------------------------------------------]  6% est: 7s 
 plot: [1,8] [==>----------------------------------------------]  7% est: 7s 
 plot: [1,9] [===>---------------------------------------------]  7% est: 7s 
 plot: [1,10] [===>--------------------------------------------]  8% est: 7s 
 plot: [1,11] [===>--------------------------------------------]  9% est: 7s 
 plot: [2,1] [====>--------------------------------------------] 10% est: 7s 
 plot: [2,2] [====>--------------------------------------------] 11% est: 7s 
 plot: [2,3] [=====>-------------------------------------------] 12% est: 7s 
 plot: [2,4] [=====>-------------------------------------------] 12% est: 7s 
 plot: [2,5] [=====>-------------------------------------------] 13% est: 7s 
 plot: [2,6] [======>------------------------------------------] 14% est: 7s 
 plot: [2,7] [======>------------------------------------------] 15% est: 7s 
 plot: [2,8] [=======>-----------------------------------------] 16% est: 7s 
 plot: [2,9] [=======>-----------------------------------------] 17% est: 7s 
 plot: [2,10] [=======>----------------------------------------] 17% est: 7s 
 plot: [2,11] [========>---------------------------------------] 18% est: 7s 
 plot: [3,1] [========>----------------------------------------] 19% est: 7s 
 plot: [3,2] [=========>---------------------------------------] 20% est: 7s 
 plot: [3,3] [=========>---------------------------------------] 21% est: 7s 
 plot: [3,4] [==========>--------------------------------------] 21% est: 7s 
 plot: [3,5] [==========>--------------------------------------] 22% est: 7s 
 plot: [3,6] [==========>--------------------------------------] 23% est: 7s 
 plot: [3,7] [===========>-------------------------------------] 24% est: 7s 
 plot: [3,8] [===========>-------------------------------------] 25% est: 7s 
 plot: [3,9] [============>------------------------------------] 26% est: 7s 
 plot: [3,10] [============>-----------------------------------] 26% est: 7s 
 plot: [3,11] [============>-----------------------------------] 27% est: 6s 
 plot: [4,1] [=============>-----------------------------------] 28% est: 6s 
 plot: [4,2] [=============>-----------------------------------] 29% est: 6s 
 plot: [4,3] [==============>----------------------------------] 30% est: 6s 
 plot: [4,4] [==============>----------------------------------] 31% est: 6s 
 plot: [4,5] [==============>----------------------------------] 31% est: 6s 
 plot: [4,6] [===============>---------------------------------] 32% est: 6s 
 plot: [4,7] [===============>---------------------------------] 33% est: 6s 
 plot: [4,8] [================>--------------------------------] 34% est: 6s 
 plot: [4,9] [================>--------------------------------] 35% est: 6s 
 plot: [4,10] [================>-------------------------------] 36% est: 6s 
 plot: [4,11] [================>-------------------------------] 36% est: 6s 
 plot: [5,1] [=================>-------------------------------] 37% est: 6s 
 plot: [5,2] [==================>------------------------------] 38% est: 6s 
 plot: [5,3] [==================>------------------------------] 39% est: 6s 
 plot: [5,4] [==================>------------------------------] 40% est: 6s 
 plot: [5,5] [===================>-----------------------------] 40% est: 6s 
 plot: [5,6] [===================>-----------------------------] 41% est: 5s 
 plot: [5,7] [====================>----------------------------] 42% est: 5s 
 plot: [5,8] [====================>----------------------------] 43% est: 5s 
 plot: [5,9] [====================>----------------------------] 44% est: 5s 
 plot: [5,10] [====================>---------------------------] 45% est: 5s 
 plot: [5,11] [=====================>--------------------------] 45% est: 5s 
 plot: [6,1] [======================>--------------------------] 46% est: 5s 
 plot: [6,2] [======================>--------------------------] 47% est: 5s 
 plot: [6,3] [======================>--------------------------] 48% est: 5s 
 plot: [6,4] [=======================>-------------------------] 49% est: 5s 
 plot: [6,5] [=======================>-------------------------] 50% est: 5s 
 plot: [6,6] [========================>------------------------] 50% est: 5s 
 plot: [6,7] [========================>------------------------] 51% est: 5s 
 plot: [6,8] [=========================>-----------------------] 52% est: 5s 
 plot: [6,9] [=========================>-----------------------] 53% est: 4s 
 plot: [6,10] [=========================>----------------------] 54% est: 4s 
 plot: [6,11] [=========================>----------------------] 55% est: 4s 
 plot: [7,1] [==========================>----------------------] 55% est: 4s 
 plot: [7,2] [===========================>---------------------] 56% est: 4s 
 plot: [7,3] [===========================>---------------------] 57% est: 4s 
 plot: [7,4] [===========================>---------------------] 58% est: 4s 
 plot: [7,5] [============================>--------------------] 59% est: 4s 
 plot: [7,6] [============================>--------------------] 60% est: 4s 
 plot: [7,7] [=============================>-------------------] 60% est: 4s 
 plot: [7,8] [=============================>-------------------] 61% est: 4s 
 plot: [7,9] [=============================>-------------------] 62% est: 4s 
 plot: [7,10] [=============================>------------------] 63% est: 4s 
 plot: [7,11] [==============================>-----------------] 64% est: 4s 
 plot: [8,1] [===============================>-----------------] 64% est: 3s 
 plot: [8,2] [===============================>-----------------] 65% est: 3s 
 plot: [8,3] [===============================>-----------------] 66% est: 3s 
 plot: [8,4] [================================>----------------] 67% est: 3s 
 plot: [8,5] [================================>----------------] 68% est: 3s 
 plot: [8,6] [=================================>---------------] 69% est: 3s 
 plot: [8,7] [=================================>---------------] 69% est: 3s 
 plot: [8,8] [=================================>---------------] 70% est: 3s 
 plot: [8,9] [==================================>--------------] 71% est: 3s 
 plot: [8,10] [==================================>-------------] 72% est: 3s 
 plot: [8,11] [==================================>-------------] 73% est: 3s 
 plot: [9,1] [===================================>-------------] 74% est: 3s 
 plot: [9,2] [===================================>-------------] 74% est: 3s 
 plot: [9,3] [====================================>------------] 75% est: 3s 
 plot: [9,4] [====================================>------------] 76% est: 2s 
 plot: [9,5] [=====================================>-----------] 77% est: 2s 
 plot: [9,6] [=====================================>-----------] 78% est: 2s 
 plot: [9,7] [=====================================>-----------] 79% est: 2s 
 plot: [9,8] [======================================>----------] 79% est: 2s 
 plot: [9,9] [======================================>----------] 80% est: 2s 
 plot: [9,10] [======================================>---------] 81% est: 2s 
 plot: [9,11] [======================================>---------] 82% est: 2s 
 plot: [10,1] [=======================================>--------] 83% est: 2s 
 plot: [10,2] [=======================================>--------] 83% est: 2s 
 plot: [10,3] [=======================================>--------] 84% est: 2s 
 plot: [10,4] [========================================>-------] 85% est: 2s 
 plot: [10,5] [========================================>-------] 86% est: 1s 
 plot: [10,6] [=========================================>------] 87% est: 1s 
 plot: [10,7] [=========================================>------] 88% est: 1s 
 plot: [10,8] [=========================================>------] 88% est: 1s 
 plot: [10,9] [==========================================>-----] 89% est: 1s 
 plot: [10,10] [=========================================>-----] 90% est: 1s 
 plot: [10,11] [==========================================>----] 91% est: 1s 
 plot: [11,1] [===========================================>----] 92% est: 1s 
 plot: [11,2] [===========================================>----] 93% est: 1s 
 plot: [11,3] [============================================>---] 93% est: 1s 
 plot: [11,4] [============================================>---] 94% est: 1s 
 plot: [11,5] [=============================================>--] 95% est: 1s 
 plot: [11,6] [=============================================>--] 96% est: 0s 
 plot: [11,7] [=============================================>--] 97% est: 0s 
 plot: [11,8] [==============================================>-] 98% est: 0s 
 plot: [11,9] [==============================================>-] 98% est: 0s 
 plot: [11,10] [==============================================>] 99% est: 0s 
 plot: [11,11] [===============================================]100% est: 0s 
                                                                             

ggpairs(kc_houses_non)

 plot: [1,1] [>------------------------------------------------]  3% est: 0s 
 plot: [1,2] [==>----------------------------------------------]  6% est: 2s 
 plot: [1,3] [===>---------------------------------------------]  8% est: 3s 
 plot: [1,4] [====>--------------------------------------------] 11% est: 3s 
 plot: [1,5] [======>------------------------------------------] 14% est: 3s 
 plot: [1,6] [=======>-----------------------------------------] 17% est: 3s 
 plot: [2,1] [=========>---------------------------------------] 19% est: 3s 
 plot: [2,2] [==========>--------------------------------------] 22% est: 4s 
 plot: [2,3] [===========>-------------------------------------] 25% est: 3s 
 plot: [2,4] [=============>-----------------------------------] 28% est: 3s 
 plot: [2,5] [==============>----------------------------------] 31% est: 4s 
 plot: [2,6] [===============>---------------------------------] 33% est: 4s 
 plot: [3,1] [=================>-------------------------------] 36% est: 4s 
 plot: [3,2] [==================>------------------------------] 39% est: 4s 
 plot: [3,3] [===================>-----------------------------] 42% est: 4s 
 plot: [3,4] [=====================>---------------------------] 44% est: 3s 
 plot: [3,5] [======================>--------------------------] 47% est: 3s 
 plot: [3,6] [=======================>-------------------------] 50% est: 3s 
 plot: [4,1] [=========================>-----------------------] 53% est: 3s 
 plot: [4,2] [==========================>----------------------] 56% est: 3s 
 plot: [4,3] [============================>--------------------] 58% est: 3s 
 plot: [4,4] [=============================>-------------------] 61% est: 3s 
 plot: [4,5] [==============================>------------------] 64% est: 3s 
 plot: [4,6] [================================>----------------] 67% est: 3s 
 plot: [5,1] [=================================>---------------] 69% est: 2s 
 plot: [5,2] [==================================>--------------] 72% est: 2s 
 plot: [5,3] [====================================>------------] 75% est: 2s 
 plot: [5,4] [=====================================>-----------] 78% est: 2s 
 plot: [5,5] [======================================>----------] 81% est: 1s 
 plot: [5,6] [========================================>--------] 83% est: 1s 
 plot: [6,1] [=========================================>-------] 86% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,2] [===========================================>-----] 89% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,3] [============================================>----] 92% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,4] [=============================================>---] 94% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,5] [===============================================>-] 97% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [=================================================]100% est: 0s 
                                                                             
ggsave("nonnumeric.png")
Saving 6.22 x 3.84 in image

 plot: [1,1] [>------------------------------------------------]  3% est: 0s 
 plot: [1,2] [==>----------------------------------------------]  6% est: 2s 
 plot: [1,3] [===>---------------------------------------------]  8% est: 3s 
 plot: [1,4] [====>--------------------------------------------] 11% est: 3s 
 plot: [1,5] [======>------------------------------------------] 14% est: 3s 
 plot: [1,6] [=======>-----------------------------------------] 17% est: 3s 
 plot: [2,1] [=========>---------------------------------------] 19% est: 3s 
 plot: [2,2] [==========>--------------------------------------] 22% est: 4s 
 plot: [2,3] [===========>-------------------------------------] 25% est: 4s 
 plot: [2,4] [=============>-----------------------------------] 28% est: 3s 
 plot: [2,5] [==============>----------------------------------] 31% est: 3s 
 plot: [2,6] [===============>---------------------------------] 33% est: 3s 
 plot: [3,1] [=================>-------------------------------] 36% est: 3s 
 plot: [3,2] [==================>------------------------------] 39% est: 3s 
 plot: [3,3] [===================>-----------------------------] 42% est: 3s 
 plot: [3,4] [=====================>---------------------------] 44% est: 3s 
 plot: [3,5] [======================>--------------------------] 47% est: 3s 
 plot: [3,6] [=======================>-------------------------] 50% est: 3s 
 plot: [4,1] [=========================>-----------------------] 53% est: 3s 
 plot: [4,2] [==========================>----------------------] 56% est: 3s 
 plot: [4,3] [============================>--------------------] 58% est: 3s 
 plot: [4,4] [=============================>-------------------] 61% est: 3s 
 plot: [4,5] [==============================>------------------] 64% est: 3s 
 plot: [4,6] [================================>----------------] 67% est: 3s 
 plot: [5,1] [=================================>---------------] 69% est: 2s 
 plot: [5,2] [==================================>--------------] 72% est: 2s 
 plot: [5,3] [====================================>------------] 75% est: 2s 
 plot: [5,4] [=====================================>-----------] 78% est: 2s 
 plot: [5,5] [======================================>----------] 81% est: 2s 
 plot: [5,6] [========================================>--------] 83% est: 1s 
 plot: [6,1] [=========================================>-------] 86% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,2] [===========================================>-----] 89% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,3] [============================================>----] 92% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,4] [=============================================>---] 94% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,5] [===============================================>-] 97% est: 0s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [=================================================]100% est: 0s 
                                                                             

waterfront, view and grade have potential sqft_living, sqft_living15, bathrooms, bedrooms, lat

model1a <- lm(price ~ sqft_living,
              data = kc_houses)

autoplot(model1a)


summary(model1a) #violates normal distribution and scale location

Call:
lm(formula = price ~ sqft_living, data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1476062  -147486   -24043   106182  4362067 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept) -43580.743   4402.690  -9.899   <2e-16 ***
sqft_living    280.624      1.936 144.920   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 261500 on 21611 degrees of freedom
Multiple R-squared:  0.4929,    Adjusted R-squared:  0.4928 
F-statistic: 2.1e+04 on 1 and 21611 DF,  p-value: < 2.2e-16
kc_houses <- kc_houses %>% 
  mutate(ln_sqft_living = log(sqft_living))

model1b <- lm(price ~ ln_sqft_living,
              data = kc_houses)

autoplot(model1b)


summary(model1b)

Call:
lm(formula = price ~ ln_sqft_living, data = kc_houses)

Residuals:
    Min      1Q  Median      3Q     Max 
-606252 -170067  -33139  106342 6183772 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -3451377      35169  -98.14   <2e-16 ***
ln_sqft_living   528648       4651  113.67   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 290400 on 21611 degrees of freedom
Multiple R-squared:  0.3742,    Adjusted R-squared:  0.3742 
F-statistic: 1.292e+04 on 1 and 21611 DF,  p-value: < 2.2e-16

reject sqft_living and ln_sqft_living based on diagnostic plots

model1c <- lm(price ~ sqft_living15,
              data = kc_houses)

autoplot(model1c)


summary(model1c)

Call:
lm(formula = price ~ sqft_living15, data = kc_houses)

Residuals:
    Min      1Q  Median      3Q     Max 
-842924 -162153  -43709   95431 6547397 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)   -82807.195   6208.029  -13.34   <2e-16 ***
sqft_living15    313.556      2.954  106.14   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 297700 on 21611 degrees of freedom
Multiple R-squared:  0.3427,    Adjusted R-squared:  0.3426 
F-statistic: 1.127e+04 on 1 and 21611 DF,  p-value: < 2.2e-16
kc_houses <- kc_houses %>% 
  mutate(ln_sqft_living15 = log(sqft_living15))

model1d <- lm(price ~ ln_sqft_living15,
              data = kc_houses)

autoplot(model1d)


summary(model1d)

Call:
lm(formula = price ~ ln_sqft_living15, data = kc_houses)

Residuals:
    Min      1Q  Median      3Q     Max 
-751080 -173399  -43738   98941 6708980 

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
(Intercept)      -4057333      48284  -84.03   <2e-16 ***
ln_sqft_living15   609783       6398   95.31   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 308100 on 21611 degrees of freedom
Multiple R-squared:  0.2959,    Adjusted R-squared:  0.2959 
F-statistic:  9083 on 1 and 21611 DF,  p-value: < 2.2e-16
model1e <- lm(price ~ bathrooms,
              data = kc_houses)

autoplot(model1e)


summary(model1e)

Call:
lm(formula = price ~ bathrooms, data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1438157  -184525   -41525   113220  5925322 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)    10708       6211   1.724   0.0847 .  
bathrooms     250326       2760  90.714   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 312400 on 21611 degrees of freedom
Multiple R-squared:  0.2758,    Adjusted R-squared:  0.2757 
F-statistic:  8229 on 1 and 21611 DF,  p-value: < 2.2e-16

kc_houses <- kc_houses %>% 
  mutate(ln_bathrooms = log(1 + bathrooms))

model1f <- lm(price ~ ln_bathrooms,
              data = kc_houses)

autoplot(model1f)


summary(model1f)

Call:
lm(formula = price ~ ln_bathrooms, data = kc_houses)

Residuals:
    Min      1Q  Median      3Q     Max 
-809328 -193575  -44701  109343 6400950 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept)   -227900       9874  -23.08   <2e-16 ***
ln_bathrooms   694945       8711   79.78   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 322700 on 21611 degrees of freedom
Multiple R-squared:  0.2275,    Adjusted R-squared:  0.2275 
F-statistic:  6365 on 1 and 21611 DF,  p-value: < 2.2e-16

waterfront, view and grade have potential

model1g <- lm(price ~ grade,
              data = kc_houses)

autoplot(model1g)
Warning: Removed 2313 row(s) containing missing values (geom_path).
Warning: Removed 1 rows containing missing values (geom_point).
Warning: Removed 1 row(s) containing missing values (geom_path).

summary(model1g)

Call:
lm(formula = price ~ grade, data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1929615  -135853   -35090    89080  5565658 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   142000     254499   0.558 0.576878    
grade3         63667     293870   0.217 0.828484    
grade4         72381     258849   0.280 0.779767    
grade5        106524     255024   0.418 0.676169    
grade6        159920     254561   0.628 0.529868    
grade7        260590     254513   1.024 0.305904    
grade8        400853     254520   1.575 0.115285    
grade9        631513     254547   2.481 0.013112 *  
grade10       929771     254611   3.652 0.000261 ***
grade11      1354842     254817   5.317 1.07e-07 ***
grade12      2049222     255909   8.008 1.23e-15 ***
grade13      3567615     264106  13.508  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 254500 on 21601 degrees of freedom
Multiple R-squared:  0.5197,    Adjusted R-squared:  0.5195 
F-statistic:  2125 on 11 and 21601 DF,  p-value: < 2.2e-16
model1h <- lm(price ~ view,
              data = kc_houses)

autoplot(model1h)


summary(model1h)

Call:
lm(formula = price ~ view, data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1211711  -196564   -67564   108436  6728035 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   496564       2399  207.02   <2e-16 ***
view1         315717      18533   17.04   <2e-16 ***
view2         295837      11054   26.76   <2e-16 ***
view3         475401      15020   31.65   <2e-16 ***
view4         967147      18901   51.17   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 334900 on 21608 degrees of freedom
Multiple R-squared:  0.1682,    Adjusted R-squared:  0.1681 
F-statistic:  1093 on 4 and 21608 DF,  p-value: < 2.2e-16

model1b has the highest r^2 and the least horiffic diagnostic plots

###second predicotr to explain residuals

price_resid <- kc_houses %>% 
  add_residuals(model1b) %>% 
  select(-c(price, grade))

price_resid %>% 
  ggpairs()

 plot: [1,1] [------------------------------------------------]  0% est: 0s 
 plot: [1,2] [------------------------------------------------]  1% est:18s 
 plot: [1,3] [------------------------------------------------]  1% est:19s 
 plot: [1,4] [>-----------------------------------------------]  1% est:20s 
 plot: [1,5] [>-----------------------------------------------]  2% est:20s 
 plot: [1,6] [>-----------------------------------------------]  2% est:20s 
 plot: [1,7] [>-----------------------------------------------]  2% est:22s 
 plot: [1,8] [>-----------------------------------------------]  2% est:24s 
 plot: [1,9] [>-----------------------------------------------]  3% est:26s 
 plot: [1,10] [>----------------------------------------------]  3% est:25s 
 plot: [1,11] [=>---------------------------------------------]  3% est:27s 
 plot: [1,12] [=>---------------------------------------------]  4% est:26s 
 plot: [1,13] [=>---------------------------------------------]  4% est:26s 
 plot: [1,14] [=>---------------------------------------------]  4% est:26s 
 plot: [1,15] [=>---------------------------------------------]  5% est:25s 
 plot: [1,16] [=>---------------------------------------------]  5% est:25s 
 plot: [1,17] [=>---------------------------------------------]  5% est:25s 
 plot: [1,18] [==>--------------------------------------------]  6% est:25s 
 plot: [2,1] [==>---------------------------------------------]  6% est:24s 
 plot: [2,2] [==>---------------------------------------------]  6% est:25s 
 plot: [2,3] [==>---------------------------------------------]  6% est:25s 
 plot: [2,4] [==>---------------------------------------------]  7% est:25s 
 plot: [2,5] [==>---------------------------------------------]  7% est:25s 
 plot: [2,6] [===>--------------------------------------------]  7% est:24s 
 plot: [2,7] [===>--------------------------------------------]  8% est:25s 
 plot: [2,8] [===>--------------------------------------------]  8% est:25s 
 plot: [2,9] [===>--------------------------------------------]  8% est:26s 
 plot: [2,10] [===>-------------------------------------------]  9% est:25s 
 plot: [2,11] [===>-------------------------------------------]  9% est:26s 
 plot: [2,12] [===>-------------------------------------------]  9% est:26s 
 plot: [2,13] [===>-------------------------------------------] 10% est:25s 
 plot: [2,14] [====>------------------------------------------] 10% est:25s 
 plot: [2,15] [====>------------------------------------------] 10% est:25s 
 plot: [2,16] [====>------------------------------------------] 10% est:25s 
 plot: [2,17] [====>------------------------------------------] 11% est:25s 
 plot: [2,18] [====>------------------------------------------] 11% est:24s 
 plot: [3,1] [====>-------------------------------------------] 11% est:24s 
 plot: [3,2] [=====>------------------------------------------] 12% est:24s 
 plot: [3,3] [=====>------------------------------------------] 12% est:25s 
 plot: [3,4] [=====>------------------------------------------] 12% est:24s 
 plot: [3,5] [=====>------------------------------------------] 13% est:24s 
 plot: [3,6] [=====>------------------------------------------] 13% est:24s 
 plot: [3,7] [=====>------------------------------------------] 13% est:24s 
 plot: [3,8] [======>-----------------------------------------] 14% est:24s 
 plot: [3,9] [======>-----------------------------------------] 14% est:24s 
 plot: [3,10] [======>----------------------------------------] 14% est:24s 
 plot: [3,11] [======>----------------------------------------] 15% est:24s 
 plot: [3,12] [======>----------------------------------------] 15% est:24s 
 plot: [3,13] [======>----------------------------------------] 15% est:24s 
 plot: [3,14] [======>----------------------------------------] 15% est:24s 
 plot: [3,15] [======>----------------------------------------] 16% est:24s 
 plot: [3,16] [=======>---------------------------------------] 16% est:24s 
 plot: [3,17] [=======>---------------------------------------] 16% est:24s 
 plot: [3,18] [=======>---------------------------------------] 17% est:23s 
 plot: [4,1] [=======>----------------------------------------] 17% est:23s 
 plot: [4,2] [=======>----------------------------------------] 17% est:23s 
 plot: [4,3] [=======>----------------------------------------] 18% est:23s 
 plot: [4,4] [========>---------------------------------------] 18% est:23s 
 plot: [4,5] [========>---------------------------------------] 18% est:23s 
 plot: [4,6] [========>---------------------------------------] 19% est:23s 
 plot: [4,7] [========>---------------------------------------] 19% est:23s 
 plot: [4,8] [========>---------------------------------------] 19% est:23s 
 plot: [4,9] [========>---------------------------------------] 19% est:23s 
 plot: [4,10] [========>--------------------------------------] 20% est:23s 
 plot: [4,11] [========>--------------------------------------] 20% est:23s 
 plot: [4,12] [=========>-------------------------------------] 20% est:23s 
 plot: [4,13] [=========>-------------------------------------] 21% est:23s 
 plot: [4,14] [=========>-------------------------------------] 21% est:23s 
 plot: [4,15] [=========>-------------------------------------] 21% est:23s 
 plot: [4,16] [=========>-------------------------------------] 22% est:23s 
 plot: [4,17] [=========>-------------------------------------] 22% est:22s 
 plot: [4,18] [=========>-------------------------------------] 22% est:22s 
 plot: [5,1] [==========>-------------------------------------] 23% est:22s 
 plot: [5,2] [==========>-------------------------------------] 23% est:22s 
 plot: [5,3] [==========>-------------------------------------] 23% est:22s 
 plot: [5,4] [==========>-------------------------------------] 23% est:22s 
 plot: [5,5] [==========>-------------------------------------] 24% est:22s 
 plot: [5,6] [===========>------------------------------------] 24% est:22s 
 plot: [5,7] [===========>------------------------------------] 24% est:22s 
 plot: [5,8] [===========>------------------------------------] 25% est:22s 
 plot: [5,9] [===========>------------------------------------] 25% est:22s 
 plot: [5,10] [===========>-----------------------------------] 25% est:22s 
 plot: [5,11] [===========>-----------------------------------] 26% est:22s 
 plot: [5,12] [===========>-----------------------------------] 26% est:22s 
 plot: [5,13] [===========>-----------------------------------] 26% est:21s 
 plot: [5,14] [===========>-----------------------------------] 27% est:21s 
 plot: [5,15] [============>----------------------------------] 27% est:21s 
 plot: [5,16] [============>----------------------------------] 27% est:21s 
 plot: [5,17] [============>----------------------------------] 27% est:21s 
 plot: [5,18] [============>----------------------------------] 28% est:21s 
 plot: [6,1] [============>-----------------------------------] 28% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,2] [=============>----------------------------------] 28% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,3] [=============>----------------------------------] 29% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,4] [=============>----------------------------------] 29% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,5] [=============>----------------------------------] 29% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [=============>----------------------------------] 30% est:22s 
 plot: [6,7] [=============>----------------------------------] 30% est:22s 
 plot: [6,8] [==============>---------------------------------] 30% est:22s 
 plot: [6,9] [==============>---------------------------------] 31% est:22s 
 plot: [6,10] [==============>--------------------------------] 31% est:22s 
 plot: [6,11] [==============>--------------------------------] 31% est:22s 
 plot: [6,12] [==============>--------------------------------] 31% est:22s 
 plot: [6,13] [==============>--------------------------------] 32% est:22s 
 plot: [6,14] [==============>--------------------------------] 32% est:22s 
 plot: [6,15] [==============>--------------------------------] 32% est:22s 
 plot: [6,16] [==============>--------------------------------] 33% est:22s 
 plot: [6,17] [===============>-------------------------------] 33% est:21s 
 plot: [6,18] [===============>-------------------------------] 33% est:21s 
 plot: [7,1] [===============>--------------------------------] 34% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,2] [===============>--------------------------------] 34% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,3] [===============>--------------------------------] 34% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,4] [================>-------------------------------] 35% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,5] [================>-------------------------------] 35% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,6] [================>-------------------------------] 35% est:24s 
 plot: [7,7] [================>-------------------------------] 35% est:24s 
 plot: [7,8] [================>-------------------------------] 36% est:24s 
 plot: [7,9] [================>-------------------------------] 36% est:24s 
 plot: [7,10] [================>------------------------------] 36% est:24s 
 plot: [7,11] [================>------------------------------] 37% est:24s 
 plot: [7,12] [================>------------------------------] 37% est:24s 
 plot: [7,13] [=================>-----------------------------] 37% est:24s 
 plot: [7,14] [=================>-----------------------------] 38% est:23s 
 plot: [7,15] [=================>-----------------------------] 38% est:23s 
 plot: [7,16] [=================>-----------------------------] 38% est:23s 
 plot: [7,17] [=================>-----------------------------] 39% est:23s 
 plot: [7,18] [=================>-----------------------------] 39% est:23s 
 plot: [8,1] [==================>-----------------------------] 39% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,2] [==================>-----------------------------] 40% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,3] [==================>-----------------------------] 40% est:24s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,4] [==================>-----------------------------] 40% est:24s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,5] [==================>-----------------------------] 40% est:24s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,6] [===================>----------------------------] 41% est:25s 
 plot: [8,7] [===================>----------------------------] 41% est:25s 
 plot: [8,8] [===================>----------------------------] 41% est:25s 
 plot: [8,9] [===================>----------------------------] 42% est:25s 
 plot: [8,10] [===================>---------------------------] 42% est:25s 
 plot: [8,11] [===================>---------------------------] 42% est:25s 
 plot: [8,12] [===================>---------------------------] 43% est:25s 
 plot: [8,13] [===================>---------------------------] 43% est:24s 
 plot: [8,14] [===================>---------------------------] 43% est:24s 
 plot: [8,15] [===================>---------------------------] 44% est:24s 
 plot: [8,16] [====================>--------------------------] 44% est:24s 
 plot: [8,17] [====================>--------------------------] 44% est:24s 
 plot: [8,18] [====================>--------------------------] 44% est:24s 
 plot: [9,1] [====================>---------------------------] 45% est:24s 
 plot: [9,2] [=====================>--------------------------] 45% est:24s 
 plot: [9,3] [=====================>--------------------------] 45% est:23s 
 plot: [9,4] [=====================>--------------------------] 46% est:23s 
 plot: [9,5] [=====================>--------------------------] 46% est:23s 
 plot: [9,6] [=====================>--------------------------] 46% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,7] [=====================>--------------------------] 47% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,8] [======================>-------------------------] 47% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,9] [======================>-------------------------] 47% est:23s 
 plot: [9,10] [=====================>-------------------------] 48% est:23s 
 plot: [9,11] [=====================>-------------------------] 48% est:23s 
 plot: [9,12] [======================>------------------------] 48% est:23s 
 plot: [9,13] [======================>------------------------] 48% est:23s 
 plot: [9,14] [======================>------------------------] 49% est:22s 
 plot: [9,15] [======================>------------------------] 49% est:22s 
 plot: [9,16] [======================>------------------------] 49% est:22s 
 plot: [9,17] [======================>------------------------] 50% est:22s 
 plot: [9,18] [=======================>-----------------------] 50% est:22s 
 plot: [10,1] [=======================>-----------------------] 50% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,2] [=======================>-----------------------] 51% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,3] [=======================>-----------------------] 51% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,4] [=======================>-----------------------] 51% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,5] [=======================>-----------------------] 52% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,6] [=======================>-----------------------] 52% est:21s 
 plot: [10,7] [========================>----------------------] 52% est:21s 
 plot: [10,8] [========================>----------------------] 52% est:21s 
 plot: [10,9] [========================>----------------------] 53% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,10] [=======================>----------------------] 53% est:21s 
 plot: [10,11] [========================>---------------------] 53% est:21s 
 plot: [10,12] [========================>---------------------] 54% est:21s 
 plot: [10,13] [========================>---------------------] 54% est:21s 
 plot: [10,14] [========================>---------------------] 54% est:20s 
 plot: [10,15] [========================>---------------------] 55% est:20s 
 plot: [10,16] [========================>---------------------] 55% est:20s 
 plot: [10,17] [========================>---------------------] 55% est:20s 
 plot: [10,18] [=========================>--------------------] 56% est:20s 
 plot: [11,1] [=========================>---------------------] 56% est:20s 
 plot: [11,2] [=========================>---------------------] 56% est:19s 
 plot: [11,3] [==========================>--------------------] 56% est:19s 
 plot: [11,4] [==========================>--------------------] 57% est:19s 
 plot: [11,5] [==========================>--------------------] 57% est:19s 
 plot: [11,6] [==========================>--------------------] 57% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,7] [==========================>--------------------] 58% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,8] [==========================>--------------------] 58% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,9] [==========================>--------------------] 58% est:19s 
 plot: [11,10] [==========================>-------------------] 59% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,11] [==========================>-------------------] 59% est:19s 
 plot: [11,12] [==========================>-------------------] 59% est:19s 
 plot: [11,13] [==========================>-------------------] 60% est:18s 
 plot: [11,14] [===========================>------------------] 60% est:18s 
 plot: [11,15] [===========================>------------------] 60% est:18s 
 plot: [11,16] [===========================>------------------] 60% est:18s 
 plot: [11,17] [===========================>------------------] 61% est:18s 
 plot: [11,18] [===========================>------------------] 61% est:17s 
 plot: [12,1] [============================>------------------] 61% est:17s 
 plot: [12,2] [============================>------------------] 62% est:17s 
 plot: [12,3] [============================>------------------] 62% est:17s 
 plot: [12,4] [============================>------------------] 62% est:17s 
 plot: [12,5] [============================>------------------] 63% est:17s 
 plot: [12,6] [=============================>-----------------] 63% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,7] [=============================>-----------------] 63% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,8] [=============================>-----------------] 64% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,9] [=============================>-----------------] 64% est:16s 
 plot: [12,10] [=============================>----------------] 64% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,11] [=============================>----------------] 65% est:16s 
 plot: [12,12] [=============================>----------------] 65% est:16s 
 plot: [12,13] [=============================>----------------] 65% est:16s 
 plot: [12,14] [=============================>----------------] 65% est:16s 
 plot: [12,15] [=============================>----------------] 66% est:16s 
 plot: [12,16] [=============================>----------------] 66% est:15s 
 plot: [12,17] [==============================>---------------] 66% est:15s 
 plot: [12,18] [==============================>---------------] 67% est:15s 
 plot: [13,1] [==============================>----------------] 67% est:15s 
 plot: [13,2] [===============================>---------------] 67% est:15s 
 plot: [13,3] [===============================>---------------] 68% est:15s 
 plot: [13,4] [===============================>---------------] 68% est:14s 
 plot: [13,5] [===============================>---------------] 68% est:14s 
 plot: [13,6] [===============================>---------------] 69% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,7] [===============================>---------------] 69% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,8] [===============================>---------------] 69% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,9] [================================>--------------] 69% est:14s 
 plot: [13,10] [===============================>--------------] 70% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,11] [===============================>--------------] 70% est:14s 
 plot: [13,12] [===============================>--------------] 70% est:14s 
 plot: [13,13] [================================>-------------] 71% est:13s 
 plot: [13,14] [================================>-------------] 71% est:13s 
 plot: [13,15] [================================>-------------] 71% est:13s 
 plot: [13,16] [================================>-------------] 72% est:13s 
 plot: [13,17] [================================>-------------] 72% est:13s 
 plot: [13,18] [================================>-------------] 72% est:13s 
 plot: [14,1] [=================================>-------------] 73% est:12s 
 plot: [14,2] [=================================>-------------] 73% est:12s 
 plot: [14,3] [=================================>-------------] 73% est:12s 
 plot: [14,4] [==================================>------------] 73% est:12s 
 plot: [14,5] [==================================>------------] 74% est:12s 
 plot: [14,6] [==================================>------------] 74% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,7] [==================================>------------] 74% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,8] [==================================>------------] 75% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,9] [==================================>------------] 75% est:12s 
 plot: [14,10] [==================================>-----------] 75% est:11s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,11] [==================================>-----------] 76% est:11s 
 plot: [14,12] [==================================>-----------] 76% est:11s 
 plot: [14,13] [==================================>-----------] 76% est:11s 
 plot: [14,14] [==================================>-----------] 77% est:11s 
 plot: [14,15] [==================================>-----------] 77% est:11s 
 plot: [14,16] [==================================>-----------] 77% est:10s 
 plot: [14,17] [===================================>----------] 77% est:10s 
 plot: [14,18] [===================================>----------] 78% est:10s 
 plot: [15,1] [====================================>----------] 78% est:10s 
 plot: [15,2] [====================================>----------] 78% est:10s 
 plot: [15,3] [====================================>----------] 79% est:10s 
 plot: [15,4] [====================================>----------] 79% est:10s 
 plot: [15,5] [====================================>----------] 79% est: 9s 
 plot: [15,6] [====================================>----------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,7] [=====================================>---------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,8] [=====================================>---------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,9] [=====================================>---------] 81% est: 9s 
 plot: [15,10] [====================================>---------] 81% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,11] [====================================>---------] 81% est: 9s 
 plot: [15,12] [====================================>---------] 81% est: 9s 
 plot: [15,13] [=====================================>--------] 82% est: 8s 
 plot: [15,14] [=====================================>--------] 82% est: 8s 
 plot: [15,15] [=====================================>--------] 82% est: 8s 
 plot: [15,16] [=====================================>--------] 83% est: 8s 
 plot: [15,17] [=====================================>--------] 83% est: 8s 
 plot: [15,18] [=====================================>--------] 83% est: 8s 
 plot: [16,1] [======================================>--------] 84% est: 8s 
 plot: [16,2] [======================================>--------] 84% est: 7s 
 plot: [16,3] [=======================================>-------] 84% est: 7s 
 plot: [16,4] [=======================================>-------] 85% est: 7s 
 plot: [16,5] [=======================================>-------] 85% est: 7s 
 plot: [16,6] [=======================================>-------] 85% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,7] [=======================================>-------] 85% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,8] [=======================================>-------] 86% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,9] [=======================================>-------] 86% est: 7s 
 plot: [16,10] [=======================================>------] 86% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,11] [=======================================>------] 87% est: 6s 
 plot: [16,12] [=======================================>------] 87% est: 6s 
 plot: [16,13] [=======================================>------] 87% est: 6s 
 plot: [16,14] [=======================================>------] 88% est: 6s 
 plot: [16,15] [=======================================>------] 88% est: 6s 
 plot: [16,16] [========================================>-----] 88% est: 5s 
 plot: [16,17] [========================================>-----] 89% est: 5s 
 plot: [16,18] [========================================>-----] 89% est: 5s 
 plot: [17,1] [=========================================>-----] 89% est: 5s 
 plot: [17,2] [=========================================>-----] 90% est: 5s 
 plot: [17,3] [=========================================>-----] 90% est: 5s 
 plot: [17,4] [=========================================>-----] 90% est: 5s 
 plot: [17,5] [==========================================>----] 90% est: 4s 
 plot: [17,6] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,7] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,8] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,9] [==========================================>----] 92% est: 4s 
 plot: [17,10] [=========================================>----] 92% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,11] [=========================================>----] 92% est: 4s 
 plot: [17,12] [==========================================>---] 93% est: 3s 
 plot: [17,13] [==========================================>---] 93% est: 3s 
 plot: [17,14] [==========================================>---] 93% est: 3s 
 plot: [17,15] [==========================================>---] 94% est: 3s 
 plot: [17,16] [==========================================>---] 94% est: 3s 
 plot: [17,17] [==========================================>---] 94% est: 3s 
 plot: [17,18] [==========================================>---] 94% est: 3s 
 plot: [18,1] [============================================>--] 95% est: 2s 
 plot: [18,2] [============================================>--] 95% est: 2s 
 plot: [18,3] [============================================>--] 95% est: 2s 
 plot: [18,4] [============================================>--] 96% est: 2s 
 plot: [18,5] [============================================>--] 96% est: 2s 
 plot: [18,6] [============================================>--] 96% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,7] [============================================>--] 97% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,8] [=============================================>-] 97% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,9] [=============================================>-] 97% est: 1s 
 plot: [18,10] [============================================>-] 98% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,11] [============================================>-] 98% est: 1s 
 plot: [18,12] [============================================>-] 98% est: 1s 
 plot: [18,13] [============================================>-] 98% est: 1s 
 plot: [18,14] [============================================>-] 99% est: 1s 
 plot: [18,15] [=============================================>] 99% est: 0s 
 plot: [18,16] [=============================================>] 99% est: 0s 
 plot: [18,17] [=============================================>]100% est: 0s 
 plot: [18,18] [==============================================]100% est: 0s 
                                                                            
ggsave("resid.png", height = 20, width = 20)

 plot: [1,1] [------------------------------------------------]  0% est: 0s 
 plot: [1,2] [------------------------------------------------]  1% est:20s 
 plot: [1,3] [------------------------------------------------]  1% est:20s 
 plot: [1,4] [>-----------------------------------------------]  1% est:21s 
 plot: [1,5] [>-----------------------------------------------]  2% est:21s 
 plot: [1,6] [>-----------------------------------------------]  2% est:21s 
 plot: [1,7] [>-----------------------------------------------]  2% est:23s 
 plot: [1,8] [>-----------------------------------------------]  2% est:25s 
 plot: [1,9] [>-----------------------------------------------]  3% est:28s 
 plot: [1,10] [>----------------------------------------------]  3% est:27s 
 plot: [1,11] [=>---------------------------------------------]  3% est:27s 
 plot: [1,12] [=>---------------------------------------------]  4% est:27s 
 plot: [1,13] [=>---------------------------------------------]  4% est:26s 
 plot: [1,14] [=>---------------------------------------------]  4% est:26s 
 plot: [1,15] [=>---------------------------------------------]  5% est:26s 
 plot: [1,16] [=>---------------------------------------------]  5% est:25s 
 plot: [1,17] [=>---------------------------------------------]  5% est:25s 
 plot: [1,18] [==>--------------------------------------------]  6% est:25s 
 plot: [2,1] [==>---------------------------------------------]  6% est:25s 
 plot: [2,2] [==>---------------------------------------------]  6% est:25s 
 plot: [2,3] [==>---------------------------------------------]  6% est:25s 
 plot: [2,4] [==>---------------------------------------------]  7% est:25s 
 plot: [2,5] [==>---------------------------------------------]  7% est:24s 
 plot: [2,6] [===>--------------------------------------------]  7% est:24s 
 plot: [2,7] [===>--------------------------------------------]  8% est:24s 
 plot: [2,8] [===>--------------------------------------------]  8% est:25s 
 plot: [2,9] [===>--------------------------------------------]  8% est:26s 
 plot: [2,10] [===>-------------------------------------------]  9% est:26s 
 plot: [2,11] [===>-------------------------------------------]  9% est:26s 
 plot: [2,12] [===>-------------------------------------------]  9% est:26s 
 plot: [2,13] [===>-------------------------------------------] 10% est:25s 
 plot: [2,14] [====>------------------------------------------] 10% est:25s 
 plot: [2,15] [====>------------------------------------------] 10% est:25s 
 plot: [2,16] [====>------------------------------------------] 10% est:25s 
 plot: [2,17] [====>------------------------------------------] 11% est:25s 
 plot: [2,18] [====>------------------------------------------] 11% est:25s 
 plot: [3,1] [====>-------------------------------------------] 11% est:25s 
 plot: [3,2] [=====>------------------------------------------] 12% est:25s 
 plot: [3,3] [=====>------------------------------------------] 12% est:24s 
 plot: [3,4] [=====>------------------------------------------] 12% est:24s 
 plot: [3,5] [=====>------------------------------------------] 13% est:24s 
 plot: [3,6] [=====>------------------------------------------] 13% est:24s 
 plot: [3,7] [=====>------------------------------------------] 13% est:24s 
 plot: [3,8] [======>-----------------------------------------] 14% est:25s 
 plot: [3,9] [======>-----------------------------------------] 14% est:25s 
 plot: [3,10] [======>----------------------------------------] 14% est:25s 
 plot: [3,11] [======>----------------------------------------] 15% est:25s 
 plot: [3,12] [======>----------------------------------------] 15% est:24s 
 plot: [3,13] [======>----------------------------------------] 15% est:24s 
 plot: [3,14] [======>----------------------------------------] 15% est:24s 
 plot: [3,15] [======>----------------------------------------] 16% est:24s 
 plot: [3,16] [=======>---------------------------------------] 16% est:24s 
 plot: [3,17] [=======>---------------------------------------] 16% est:24s 
 plot: [3,18] [=======>---------------------------------------] 17% est:24s 
 plot: [4,1] [=======>----------------------------------------] 17% est:23s 
 plot: [4,2] [=======>----------------------------------------] 17% est:23s 
 plot: [4,3] [=======>----------------------------------------] 18% est:23s 
 plot: [4,4] [========>---------------------------------------] 18% est:23s 
 plot: [4,5] [========>---------------------------------------] 18% est:23s 
 plot: [4,6] [========>---------------------------------------] 19% est:23s 
 plot: [4,7] [========>---------------------------------------] 19% est:23s 
 plot: [4,8] [========>---------------------------------------] 19% est:23s 
 plot: [4,9] [========>---------------------------------------] 19% est:24s 
 plot: [4,10] [========>--------------------------------------] 20% est:23s 
 plot: [4,11] [========>--------------------------------------] 20% est:23s 
 plot: [4,12] [=========>-------------------------------------] 20% est:23s 
 plot: [4,13] [=========>-------------------------------------] 21% est:23s 
 plot: [4,14] [=========>-------------------------------------] 21% est:23s 
 plot: [4,15] [=========>-------------------------------------] 21% est:23s 
 plot: [4,16] [=========>-------------------------------------] 22% est:23s 
 plot: [4,17] [=========>-------------------------------------] 22% est:23s 
 plot: [4,18] [=========>-------------------------------------] 22% est:22s 
 plot: [5,1] [==========>-------------------------------------] 23% est:22s 
 plot: [5,2] [==========>-------------------------------------] 23% est:22s 
 plot: [5,3] [==========>-------------------------------------] 23% est:22s 
 plot: [5,4] [==========>-------------------------------------] 23% est:22s 
 plot: [5,5] [==========>-------------------------------------] 24% est:22s 
 plot: [5,6] [===========>------------------------------------] 24% est:22s 
 plot: [5,7] [===========>------------------------------------] 24% est:22s 
 plot: [5,8] [===========>------------------------------------] 25% est:22s 
 plot: [5,9] [===========>------------------------------------] 25% est:22s 
 plot: [5,10] [===========>-----------------------------------] 25% est:22s 
 plot: [5,11] [===========>-----------------------------------] 26% est:22s 
 plot: [5,12] [===========>-----------------------------------] 26% est:22s 
 plot: [5,13] [===========>-----------------------------------] 26% est:22s 
 plot: [5,14] [===========>-----------------------------------] 27% est:21s 
 plot: [5,15] [============>----------------------------------] 27% est:21s 
 plot: [5,16] [============>----------------------------------] 27% est:21s 
 plot: [5,17] [============>----------------------------------] 27% est:21s 
 plot: [5,18] [============>----------------------------------] 28% est:21s 
 plot: [6,1] [============>-----------------------------------] 28% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,2] [=============>----------------------------------] 28% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,3] [=============>----------------------------------] 29% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,4] [=============>----------------------------------] 29% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,5] [=============>----------------------------------] 29% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [=============>----------------------------------] 30% est:22s 
 plot: [6,7] [=============>----------------------------------] 30% est:22s 
 plot: [6,8] [==============>---------------------------------] 30% est:22s 
 plot: [6,9] [==============>---------------------------------] 31% est:22s 
 plot: [6,10] [==============>--------------------------------] 31% est:22s 
 plot: [6,11] [==============>--------------------------------] 31% est:22s 
 plot: [6,12] [==============>--------------------------------] 31% est:22s 
 plot: [6,13] [==============>--------------------------------] 32% est:22s 
 plot: [6,14] [==============>--------------------------------] 32% est:22s 
 plot: [6,15] [==============>--------------------------------] 32% est:21s 
 plot: [6,16] [==============>--------------------------------] 33% est:21s 
 plot: [6,17] [===============>-------------------------------] 33% est:21s 
 plot: [6,18] [===============>-------------------------------] 33% est:21s 
 plot: [7,1] [===============>--------------------------------] 34% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,2] [===============>--------------------------------] 34% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,3] [===============>--------------------------------] 34% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,4] [================>-------------------------------] 35% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,5] [================>-------------------------------] 35% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,6] [================>-------------------------------] 35% est:24s 
 plot: [7,7] [================>-------------------------------] 35% est:24s 
 plot: [7,8] [================>-------------------------------] 36% est:24s 
 plot: [7,9] [================>-------------------------------] 36% est:24s 
 plot: [7,10] [================>------------------------------] 36% est:24s 
 plot: [7,11] [================>------------------------------] 37% est:23s 
 plot: [7,12] [================>------------------------------] 37% est:23s 
 plot: [7,13] [=================>-----------------------------] 37% est:23s 
 plot: [7,14] [=================>-----------------------------] 38% est:23s 
 plot: [7,15] [=================>-----------------------------] 38% est:23s 
 plot: [7,16] [=================>-----------------------------] 38% est:23s 
 plot: [7,17] [=================>-----------------------------] 39% est:23s 
 plot: [7,18] [=================>-----------------------------] 39% est:23s 
 plot: [8,1] [==================>-----------------------------] 39% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,2] [==================>-----------------------------] 40% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,3] [==================>-----------------------------] 40% est:24s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,4] [==================>-----------------------------] 40% est:24s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,5] [==================>-----------------------------] 40% est:24s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,6] [===================>----------------------------] 41% est:25s 
 plot: [8,7] [===================>----------------------------] 41% est:25s 
 plot: [8,8] [===================>----------------------------] 41% est:25s 
 plot: [8,9] [===================>----------------------------] 42% est:25s 
 plot: [8,10] [===================>---------------------------] 42% est:25s 
 plot: [8,11] [===================>---------------------------] 42% est:24s 
 plot: [8,12] [===================>---------------------------] 43% est:24s 
 plot: [8,13] [===================>---------------------------] 43% est:24s 
 plot: [8,14] [===================>---------------------------] 43% est:24s 
 plot: [8,15] [===================>---------------------------] 44% est:24s 
 plot: [8,16] [====================>--------------------------] 44% est:24s 
 plot: [8,17] [====================>--------------------------] 44% est:24s 
 plot: [8,18] [====================>--------------------------] 44% est:24s 
 plot: [9,1] [====================>---------------------------] 45% est:24s 
 plot: [9,2] [=====================>--------------------------] 45% est:24s 
 plot: [9,3] [=====================>--------------------------] 45% est:23s 
 plot: [9,4] [=====================>--------------------------] 46% est:23s 
 plot: [9,5] [=====================>--------------------------] 46% est:23s 
 plot: [9,6] [=====================>--------------------------] 46% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,7] [=====================>--------------------------] 47% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,8] [======================>-------------------------] 47% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,9] [======================>-------------------------] 47% est:23s 
 plot: [9,10] [=====================>-------------------------] 48% est:23s 
 plot: [9,11] [=====================>-------------------------] 48% est:23s 
 plot: [9,12] [======================>------------------------] 48% est:23s 
 plot: [9,13] [======================>------------------------] 48% est:23s 
 plot: [9,14] [======================>------------------------] 49% est:22s 
 plot: [9,15] [======================>------------------------] 49% est:22s 
 plot: [9,16] [======================>------------------------] 49% est:22s 
 plot: [9,17] [======================>------------------------] 50% est:22s 
 plot: [9,18] [=======================>-----------------------] 50% est:22s 
 plot: [10,1] [=======================>-----------------------] 50% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,2] [=======================>-----------------------] 51% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,3] [=======================>-----------------------] 51% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,4] [=======================>-----------------------] 51% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,5] [=======================>-----------------------] 52% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,6] [=======================>-----------------------] 52% est:21s 
 plot: [10,7] [========================>----------------------] 52% est:21s 
 plot: [10,8] [========================>----------------------] 52% est:21s 
 plot: [10,9] [========================>----------------------] 53% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,10] [=======================>----------------------] 53% est:21s 
 plot: [10,11] [========================>---------------------] 53% est:21s 
 plot: [10,12] [========================>---------------------] 54% est:21s 
 plot: [10,13] [========================>---------------------] 54% est:20s 
 plot: [10,14] [========================>---------------------] 54% est:20s 
 plot: [10,15] [========================>---------------------] 55% est:20s 
 plot: [10,16] [========================>---------------------] 55% est:20s 
 plot: [10,17] [========================>---------------------] 55% est:20s 
 plot: [10,18] [=========================>--------------------] 56% est:20s 
 plot: [11,1] [=========================>---------------------] 56% est:20s 
 plot: [11,2] [=========================>---------------------] 56% est:19s 
 plot: [11,3] [==========================>--------------------] 56% est:19s 
 plot: [11,4] [==========================>--------------------] 57% est:19s 
 plot: [11,5] [==========================>--------------------] 57% est:19s 
 plot: [11,6] [==========================>--------------------] 57% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,7] [==========================>--------------------] 58% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,8] [==========================>--------------------] 58% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,9] [==========================>--------------------] 58% est:19s 
 plot: [11,10] [==========================>-------------------] 59% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,11] [==========================>-------------------] 59% est:19s 
 plot: [11,12] [==========================>-------------------] 59% est:18s 
 plot: [11,13] [==========================>-------------------] 60% est:18s 
 plot: [11,14] [===========================>------------------] 60% est:18s 
 plot: [11,15] [===========================>------------------] 60% est:18s 
 plot: [11,16] [===========================>------------------] 60% est:18s 
 plot: [11,17] [===========================>------------------] 61% est:18s 
 plot: [11,18] [===========================>------------------] 61% est:17s 
 plot: [12,1] [============================>------------------] 61% est:17s 
 plot: [12,2] [============================>------------------] 62% est:17s 
 plot: [12,3] [============================>------------------] 62% est:17s 
 plot: [12,4] [============================>------------------] 62% est:17s 
 plot: [12,5] [============================>------------------] 63% est:17s 
 plot: [12,6] [=============================>-----------------] 63% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,7] [=============================>-----------------] 63% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,8] [=============================>-----------------] 64% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,9] [=============================>-----------------] 64% est:16s 
 plot: [12,10] [=============================>----------------] 64% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,11] [=============================>----------------] 65% est:16s 
 plot: [12,12] [=============================>----------------] 65% est:16s 
 plot: [12,13] [=============================>----------------] 65% est:16s 
 plot: [12,14] [=============================>----------------] 65% est:16s 
 plot: [12,15] [=============================>----------------] 66% est:16s 
 plot: [12,16] [=============================>----------------] 66% est:15s 
 plot: [12,17] [==============================>---------------] 66% est:15s 
 plot: [12,18] [==============================>---------------] 67% est:15s 
 plot: [13,1] [==============================>----------------] 67% est:15s 
 plot: [13,2] [===============================>---------------] 67% est:15s 
 plot: [13,3] [===============================>---------------] 68% est:15s 
 plot: [13,4] [===============================>---------------] 68% est:14s 
 plot: [13,5] [===============================>---------------] 68% est:14s 
 plot: [13,6] [===============================>---------------] 69% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,7] [===============================>---------------] 69% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,8] [===============================>---------------] 69% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,9] [================================>--------------] 69% est:14s 
 plot: [13,10] [===============================>--------------] 70% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,11] [===============================>--------------] 70% est:14s 
 plot: [13,12] [===============================>--------------] 70% est:14s 
 plot: [13,13] [================================>-------------] 71% est:13s 
 plot: [13,14] [================================>-------------] 71% est:13s 
 plot: [13,15] [================================>-------------] 71% est:13s 
 plot: [13,16] [================================>-------------] 72% est:13s 
 plot: [13,17] [================================>-------------] 72% est:13s 
 plot: [13,18] [================================>-------------] 72% est:13s 
 plot: [14,1] [=================================>-------------] 73% est:12s 
 plot: [14,2] [=================================>-------------] 73% est:12s 
 plot: [14,3] [=================================>-------------] 73% est:12s 
 plot: [14,4] [==================================>------------] 73% est:12s 
 plot: [14,5] [==================================>------------] 74% est:12s 
 plot: [14,6] [==================================>------------] 74% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,7] [==================================>------------] 74% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,8] [==================================>------------] 75% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,9] [==================================>------------] 75% est:12s 
 plot: [14,10] [==================================>-----------] 75% est:11s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,11] [==================================>-----------] 76% est:11s 
 plot: [14,12] [==================================>-----------] 76% est:11s 
 plot: [14,13] [==================================>-----------] 76% est:11s 
 plot: [14,14] [==================================>-----------] 77% est:11s 
 plot: [14,15] [==================================>-----------] 77% est:11s 
 plot: [14,16] [==================================>-----------] 77% est:10s 
 plot: [14,17] [===================================>----------] 77% est:10s 
 plot: [14,18] [===================================>----------] 78% est:10s 
 plot: [15,1] [====================================>----------] 78% est:10s 
 plot: [15,2] [====================================>----------] 78% est:10s 
 plot: [15,3] [====================================>----------] 79% est:10s 
 plot: [15,4] [====================================>----------] 79% est:10s 
 plot: [15,5] [====================================>----------] 79% est: 9s 
 plot: [15,6] [====================================>----------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,7] [=====================================>---------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,8] [=====================================>---------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,9] [=====================================>---------] 81% est: 9s 
 plot: [15,10] [====================================>---------] 81% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,11] [====================================>---------] 81% est: 9s 
 plot: [15,12] [====================================>---------] 81% est: 9s 
 plot: [15,13] [=====================================>--------] 82% est: 8s 
 plot: [15,14] [=====================================>--------] 82% est: 8s 
 plot: [15,15] [=====================================>--------] 82% est: 8s 
 plot: [15,16] [=====================================>--------] 83% est: 8s 
 plot: [15,17] [=====================================>--------] 83% est: 8s 
 plot: [15,18] [=====================================>--------] 83% est: 8s 
 plot: [16,1] [======================================>--------] 84% est: 7s 
 plot: [16,2] [======================================>--------] 84% est: 7s 
 plot: [16,3] [=======================================>-------] 84% est: 7s 
 plot: [16,4] [=======================================>-------] 85% est: 7s 
 plot: [16,5] [=======================================>-------] 85% est: 7s 
 plot: [16,6] [=======================================>-------] 85% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,7] [=======================================>-------] 85% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,8] [=======================================>-------] 86% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,9] [=======================================>-------] 86% est: 6s 
 plot: [16,10] [=======================================>------] 86% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,11] [=======================================>------] 87% est: 6s 
 plot: [16,12] [=======================================>------] 87% est: 6s 
 plot: [16,13] [=======================================>------] 87% est: 6s 
 plot: [16,14] [=======================================>------] 88% est: 6s 
 plot: [16,15] [=======================================>------] 88% est: 6s 
 plot: [16,16] [========================================>-----] 88% est: 5s 
 plot: [16,17] [========================================>-----] 89% est: 5s 
 plot: [16,18] [========================================>-----] 89% est: 5s 
 plot: [17,1] [=========================================>-----] 89% est: 5s 
 plot: [17,2] [=========================================>-----] 90% est: 5s 
 plot: [17,3] [=========================================>-----] 90% est: 5s 
 plot: [17,4] [=========================================>-----] 90% est: 5s 
 plot: [17,5] [==========================================>----] 90% est: 4s 
 plot: [17,6] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,7] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,8] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,9] [==========================================>----] 92% est: 4s 
 plot: [17,10] [=========================================>----] 92% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,11] [=========================================>----] 92% est: 4s 
 plot: [17,12] [==========================================>---] 93% est: 3s 
 plot: [17,13] [==========================================>---] 93% est: 3s 
 plot: [17,14] [==========================================>---] 93% est: 3s 
 plot: [17,15] [==========================================>---] 94% est: 3s 
 plot: [17,16] [==========================================>---] 94% est: 3s 
 plot: [17,17] [==========================================>---] 94% est: 3s 
 plot: [17,18] [==========================================>---] 94% est: 3s 
 plot: [18,1] [============================================>--] 95% est: 2s 
 plot: [18,2] [============================================>--] 95% est: 2s 
 plot: [18,3] [============================================>--] 95% est: 2s 
 plot: [18,4] [============================================>--] 96% est: 2s 
 plot: [18,5] [============================================>--] 96% est: 2s 
 plot: [18,6] [============================================>--] 96% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,7] [============================================>--] 97% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,8] [=============================================>-] 97% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,9] [=============================================>-] 97% est: 1s 
 plot: [18,10] [============================================>-] 98% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [18,11] [============================================>-] 98% est: 1s 
 plot: [18,12] [============================================>-] 98% est: 1s 
 plot: [18,13] [============================================>-] 98% est: 1s 
 plot: [18,14] [============================================>-] 99% est: 1s 
 plot: [18,15] [=============================================>] 99% est: 0s 
 plot: [18,16] [=============================================>] 99% est: 0s 
 plot: [18,17] [=============================================>]100% est: 0s 
 plot: [18,18] [==============================================]100% est: 0s 
                                                                            

latitude

summary(model2a)

Call:
lm(formula = price ~ ln_sqft_living + lat, data = kc_houses)

Residuals:
    Min      1Q  Median      3Q     Max 
-666157 -143836  -39236   84919 6149214 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -39084630     633250  -61.72   <2e-16 ***
ln_sqft_living    519005       4346  119.42   <2e-16 ***
lat               750757      13324   56.35   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 271200 on 21610 degrees of freedom
Multiple R-squared:  0.4543,    Adjusted R-squared:  0.4543 
F-statistic:  8997 on 2 and 21610 DF,  p-value: < 2.2e-16
model2b <- lm(price ~ ln_sqft_living + grade,
              data = kc_houses)

autoplot(model2b)
Warning: Removed 5684 row(s) containing missing values (geom_path).
Warning: Removed 1 rows containing missing values (geom_point).
Warning: Removed 1 row(s) containing missing values (geom_path).

summary(model2b)

Call:
lm(formula = price ~ ln_sqft_living + grade, data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1831009  -132953   -29074    91804  5350712 

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -1292505     246541  -5.243 1.60e-07 ***
ln_sqft_living   253004       5886  42.983  < 2e-16 ***
grade3          -117518     282092  -0.417  0.67698    
grade4          -122997     248489  -0.495  0.62062    
grade5          -186446     244871  -0.761  0.44642    
grade6          -185092     244464  -0.757  0.44898    
grade7          -174110     244495  -0.712  0.47640    
grade8          -100494     244570  -0.411  0.68115    
grade9            58723     244682   0.240  0.81033    
grade10          304045     244813   1.242  0.21427    
grade11          673027     245092   2.746  0.00604 ** 
grade12         1314002     246220   5.337 9.56e-08 ***
grade13         2754255     254198  10.835  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 244300 on 21600 degrees of freedom
Multiple R-squared:  0.5575,    Adjusted R-squared:  0.5573 
F-statistic:  2268 on 12 and 21600 DF,  p-value: < 2.2e-16
anova(model1b, model2b)
Analysis of Variance Table

Model 1: price ~ ln_sqft_living
Model 2: price ~ ln_sqft_living + grade
  Res.Df        RSS Df  Sum of Sq      F    Pr(>F)    
1  21611 1.8230e+15                                   
2  21600 1.2888e+15 11 5.3411e+14 813.75 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

include all levels in our model due to statistical significance 2b is champ!!

###third predictor

price_resid <- kc_houses %>% 
  add_residuals(model2b) %>% 
  select(-c(price, ln_sqft_living, grade))

price_resid %>% 
  ggpairs()

 plot: [1,1] [------------------------------------------------]  0% est: 0s 
 plot: [1,2] [------------------------------------------------]  1% est:15s 
 plot: [1,3] [------------------------------------------------]  1% est:15s 
 plot: [1,4] [>-----------------------------------------------]  1% est:21s 
 plot: [1,5] [>-----------------------------------------------]  2% est:21s 
 plot: [1,6] [>-----------------------------------------------]  2% est:21s 
 plot: [1,7] [>-----------------------------------------------]  2% est:22s 
 plot: [1,8] [>-----------------------------------------------]  3% est:24s 
 plot: [1,9] [>-----------------------------------------------]  3% est:26s 
 plot: [1,10] [=>---------------------------------------------]  3% est:27s 
 plot: [1,11] [=>---------------------------------------------]  4% est:27s 
 plot: [1,12] [=>---------------------------------------------]  4% est:26s 
 plot: [1,13] [=>---------------------------------------------]  4% est:25s 
 plot: [1,14] [=>---------------------------------------------]  5% est:26s 
 plot: [1,15] [=>---------------------------------------------]  5% est:25s 
 plot: [1,16] [==>--------------------------------------------]  6% est:25s 
 plot: [1,17] [==>--------------------------------------------]  6% est:25s 
 plot: [2,1] [==>---------------------------------------------]  6% est:24s 
 plot: [2,2] [==>---------------------------------------------]  7% est:24s 
 plot: [2,3] [==>---------------------------------------------]  7% est:24s 
 plot: [2,4] [==>---------------------------------------------]  7% est:24s 
 plot: [2,5] [===>--------------------------------------------]  8% est:24s 
 plot: [2,6] [===>--------------------------------------------]  8% est:24s 
 plot: [2,7] [===>--------------------------------------------]  8% est:25s 
 plot: [2,8] [===>--------------------------------------------]  9% est:25s 
 plot: [2,9] [===>--------------------------------------------]  9% est:25s 
 plot: [2,10] [===>-------------------------------------------]  9% est:25s 
 plot: [2,11] [====>------------------------------------------] 10% est:25s 
 plot: [2,12] [====>------------------------------------------] 10% est:25s 
 plot: [2,13] [====>------------------------------------------] 10% est:25s 
 plot: [2,14] [====>------------------------------------------] 11% est:25s 
 plot: [2,15] [====>------------------------------------------] 11% est:24s 
 plot: [2,16] [====>------------------------------------------] 11% est:24s 
 plot: [2,17] [=====>-----------------------------------------] 12% est:24s 
 plot: [3,1] [=====>------------------------------------------] 12% est:24s 
 plot: [3,2] [=====>------------------------------------------] 12% est:24s 
 plot: [3,3] [=====>------------------------------------------] 13% est:24s 
 plot: [3,4] [=====>------------------------------------------] 13% est:24s 
 plot: [3,5] [=====>------------------------------------------] 13% est:23s 
 plot: [3,6] [======>-----------------------------------------] 14% est:23s 
 plot: [3,7] [======>-----------------------------------------] 14% est:23s 
 plot: [3,8] [======>-----------------------------------------] 15% est:24s 
 plot: [3,9] [======>-----------------------------------------] 15% est:24s 
 plot: [3,10] [======>----------------------------------------] 15% est:24s 
 plot: [3,11] [======>----------------------------------------] 16% est:24s 
 plot: [3,12] [======>----------------------------------------] 16% est:23s 
 plot: [3,13] [=======>---------------------------------------] 16% est:23s 
 plot: [3,14] [=======>---------------------------------------] 17% est:23s 
 plot: [3,15] [=======>---------------------------------------] 17% est:23s 
 plot: [3,16] [=======>---------------------------------------] 17% est:23s 
 plot: [3,17] [=======>---------------------------------------] 18% est:23s 
 plot: [4,1] [========>---------------------------------------] 18% est:22s 
 plot: [4,2] [========>---------------------------------------] 18% est:22s 
 plot: [4,3] [========>---------------------------------------] 19% est:22s 
 plot: [4,4] [========>---------------------------------------] 19% est:22s 
 plot: [4,5] [========>---------------------------------------] 19% est:22s 
 plot: [4,6] [========>---------------------------------------] 20% est:22s 
 plot: [4,7] [=========>--------------------------------------] 20% est:22s 
 plot: [4,8] [=========>--------------------------------------] 20% est:22s 
 plot: [4,9] [=========>--------------------------------------] 21% est:22s 
 plot: [4,10] [=========>-------------------------------------] 21% est:22s 
 plot: [4,11] [=========>-------------------------------------] 21% est:22s 
 plot: [4,12] [=========>-------------------------------------] 22% est:22s 
 plot: [4,13] [=========>-------------------------------------] 22% est:22s 
 plot: [4,14] [==========>------------------------------------] 22% est:22s 
 plot: [4,15] [==========>------------------------------------] 23% est:21s 
 plot: [4,16] [==========>------------------------------------] 23% est:22s 
 plot: [4,17] [==========>------------------------------------] 24% est:21s 
 plot: [5,1] [==========>-------------------------------------] 24% est:21s 
 plot: [5,2] [===========>------------------------------------] 24% est:21s 
 plot: [5,3] [===========>------------------------------------] 25% est:21s 
 plot: [5,4] [===========>------------------------------------] 25% est:21s 
 plot: [5,5] [===========>------------------------------------] 25% est:21s 
 plot: [5,6] [===========>------------------------------------] 26% est:21s 
 plot: [5,7] [===========>------------------------------------] 26% est:21s 
 plot: [5,8] [============>-----------------------------------] 26% est:21s 
 plot: [5,9] [============>-----------------------------------] 27% est:21s 
 plot: [5,10] [============>----------------------------------] 27% est:21s 
 plot: [5,11] [============>----------------------------------] 27% est:21s 
 plot: [5,12] [============>----------------------------------] 28% est:21s 
 plot: [5,13] [============>----------------------------------] 28% est:21s 
 plot: [5,14] [============>----------------------------------] 28% est:20s 
 plot: [5,15] [============>----------------------------------] 29% est:20s 
 plot: [5,16] [=============>---------------------------------] 29% est:20s 
 plot: [5,17] [=============>---------------------------------] 29% est:20s 
 plot: [6,1] [=============>----------------------------------] 30% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,2] [=============>----------------------------------] 30% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,3] [==============>---------------------------------] 30% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,4] [==============>---------------------------------] 31% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,5] [==============>---------------------------------] 31% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [==============>---------------------------------] 31% est:21s 
 plot: [6,7] [==============>---------------------------------] 32% est:21s 
 plot: [6,8] [==============>---------------------------------] 32% est:21s 
 plot: [6,9] [===============>--------------------------------] 33% est:21s 
 plot: [6,10] [==============>--------------------------------] 33% est:21s 
 plot: [6,11] [===============>-------------------------------] 33% est:21s 
 plot: [6,12] [===============>-------------------------------] 34% est:21s 
 plot: [6,13] [===============>-------------------------------] 34% est:20s 
 plot: [6,14] [===============>-------------------------------] 34% est:20s 
 plot: [6,15] [===============>-------------------------------] 35% est:20s 
 plot: [6,16] [===============>-------------------------------] 35% est:20s 
 plot: [6,17] [================>------------------------------] 35% est:20s 
 plot: [7,1] [================>-------------------------------] 36% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,2] [================>-------------------------------] 36% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,3] [================>-------------------------------] 36% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,4] [=================>------------------------------] 37% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,5] [=================>------------------------------] 37% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,6] [=================>------------------------------] 37% est:23s 
 plot: [7,7] [=================>------------------------------] 38% est:23s 
 plot: [7,8] [=================>------------------------------] 38% est:23s 
 plot: [7,9] [=================>------------------------------] 38% est:23s 
 plot: [7,10] [=================>-----------------------------] 39% est:22s 
 plot: [7,11] [=================>-----------------------------] 39% est:22s 
 plot: [7,12] [==================>----------------------------] 39% est:22s 
 plot: [7,13] [==================>----------------------------] 40% est:22s 
 plot: [7,14] [==================>----------------------------] 40% est:22s 
 plot: [7,15] [==================>----------------------------] 40% est:22s 
 plot: [7,16] [==================>----------------------------] 41% est:22s 
 plot: [7,17] [==================>----------------------------] 41% est:22s 
 plot: [8,1] [===================>----------------------------] 42% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,2] [===================>----------------------------] 42% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,3] [===================>----------------------------] 42% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,4] [===================>----------------------------] 43% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,5] [====================>---------------------------] 43% est:23s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,6] [====================>---------------------------] 43% est:24s 
 plot: [8,7] [====================>---------------------------] 44% est:24s 
 plot: [8,8] [====================>---------------------------] 44% est:24s 
 plot: [8,9] [====================>---------------------------] 44% est:24s 
 plot: [8,10] [====================>--------------------------] 45% est:23s 
 plot: [8,11] [====================>--------------------------] 45% est:23s 
 plot: [8,12] [====================>--------------------------] 45% est:23s 
 plot: [8,13] [====================>--------------------------] 46% est:23s 
 plot: [8,14] [=====================>-------------------------] 46% est:23s 
 plot: [8,15] [=====================>-------------------------] 46% est:23s 
 plot: [8,16] [=====================>-------------------------] 47% est:23s 
 plot: [8,17] [=====================>-------------------------] 47% est:22s 
 plot: [9,1] [======================>-------------------------] 47% est:22s 
 plot: [9,2] [======================>-------------------------] 48% est:22s 
 plot: [9,3] [======================>-------------------------] 48% est:22s 
 plot: [9,4] [======================>-------------------------] 48% est:22s 
 plot: [9,5] [======================>-------------------------] 49% est:22s 
 plot: [9,6] [=======================>------------------------] 49% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,7] [=======================>------------------------] 49% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,8] [=======================>------------------------] 50% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,9] [=======================>------------------------] 50% est:22s 
 plot: [9,10] [=======================>-----------------------] 51% est:22s 
 plot: [9,11] [=======================>-----------------------] 51% est:21s 
 plot: [9,12] [=======================>-----------------------] 51% est:21s 
 plot: [9,13] [=======================>-----------------------] 52% est:21s 
 plot: [9,14] [=======================>-----------------------] 52% est:21s 
 plot: [9,15] [========================>----------------------] 52% est:21s 
 plot: [9,16] [========================>----------------------] 53% est:20s 
 plot: [9,17] [========================>----------------------] 53% est:20s 
 plot: [10,1] [========================>----------------------] 53% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,2] [========================>----------------------] 54% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,3] [========================>----------------------] 54% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,4] [=========================>---------------------] 54% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,5] [=========================>---------------------] 55% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,6] [=========================>---------------------] 55% est:20s 
 plot: [10,7] [=========================>---------------------] 55% est:20s 
 plot: [10,8] [=========================>---------------------] 56% est:19s 
 plot: [10,9] [=========================>---------------------] 56% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,10] [=========================>--------------------] 56% est:19s 
 plot: [10,11] [=========================>--------------------] 57% est:19s 
 plot: [10,12] [=========================>--------------------] 57% est:19s 
 plot: [10,13] [=========================>--------------------] 57% est:19s 
 plot: [10,14] [==========================>-------------------] 58% est:19s 
 plot: [10,15] [==========================>-------------------] 58% est:18s 
 plot: [10,16] [==========================>-------------------] 58% est:18s 
 plot: [10,17] [==========================>-------------------] 59% est:18s 
 plot: [11,1] [===========================>-------------------] 59% est:18s 
 plot: [11,2] [===========================>-------------------] 60% est:18s 
 plot: [11,3] [===========================>-------------------] 60% est:18s 
 plot: [11,4] [===========================>-------------------] 60% est:17s 
 plot: [11,5] [===========================>-------------------] 61% est:17s 
 plot: [11,6] [============================>------------------] 61% est:17s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,7] [============================>------------------] 61% est:17s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,8] [============================>------------------] 62% est:17s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,9] [============================>------------------] 62% est:17s 
 plot: [11,10] [============================>-----------------] 62% est:17s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,11] [============================>-----------------] 63% est:17s 
 plot: [11,12] [============================>-----------------] 63% est:17s 
 plot: [11,13] [============================>-----------------] 63% est:17s 
 plot: [11,14] [============================>-----------------] 64% est:16s 
 plot: [11,15] [============================>-----------------] 64% est:16s 
 plot: [11,16] [=============================>----------------] 64% est:16s 
 plot: [11,17] [=============================>----------------] 65% est:16s 
 plot: [12,1] [==============================>----------------] 65% est:16s 
 plot: [12,2] [==============================>----------------] 65% est:15s 
 plot: [12,3] [==============================>----------------] 66% est:15s 
 plot: [12,4] [==============================>----------------] 66% est:15s 
 plot: [12,5] [==============================>----------------] 66% est:15s 
 plot: [12,6] [==============================>----------------] 67% est:15s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,7] [===============================>---------------] 67% est:15s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,8] [===============================>---------------] 67% est:15s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,9] [===============================>---------------] 68% est:15s 
 plot: [12,10] [==============================>---------------] 68% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,11] [===============================>--------------] 69% est:14s 
 plot: [12,12] [===============================>--------------] 69% est:14s 
 plot: [12,13] [===============================>--------------] 69% est:14s 
 plot: [12,14] [===============================>--------------] 70% est:14s 
 plot: [12,15] [===============================>--------------] 70% est:14s 
 plot: [12,16] [===============================>--------------] 70% est:13s 
 plot: [12,17] [===============================>--------------] 71% est:13s 
 plot: [13,1] [================================>--------------] 71% est:13s 
 plot: [13,2] [=================================>-------------] 71% est:13s 
 plot: [13,3] [=================================>-------------] 72% est:13s 
 plot: [13,4] [=================================>-------------] 72% est:12s 
 plot: [13,5] [=================================>-------------] 72% est:12s 
 plot: [13,6] [=================================>-------------] 73% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,7] [=================================>-------------] 73% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,8] [=================================>-------------] 73% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,9] [==================================>------------] 74% est:12s 
 plot: [13,10] [=================================>------------] 74% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,11] [=================================>------------] 74% est:12s 
 plot: [13,12] [=================================>------------] 75% est:11s 
 plot: [13,13] [==================================>-----------] 75% est:11s 
 plot: [13,14] [==================================>-----------] 75% est:11s 
 plot: [13,15] [==================================>-----------] 76% est:11s 
 plot: [13,16] [==================================>-----------] 76% est:11s 
 plot: [13,17] [==================================>-----------] 76% est:10s 
 plot: [14,1] [===================================>-----------] 77% est:10s 
 plot: [14,2] [===================================>-----------] 77% est:10s 
 plot: [14,3] [===================================>-----------] 78% est:10s 
 plot: [14,4] [====================================>----------] 78% est:10s 
 plot: [14,5] [====================================>----------] 78% est:10s 
 plot: [14,6] [====================================>----------] 79% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,7] [====================================>----------] 79% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,8] [====================================>----------] 79% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,9] [====================================>----------] 80% est: 9s 
 plot: [14,10] [====================================>---------] 80% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,11] [====================================>---------] 80% est: 9s 
 plot: [14,12] [====================================>---------] 81% est: 9s 
 plot: [14,13] [====================================>---------] 81% est: 9s 
 plot: [14,14] [====================================>---------] 81% est: 8s 
 plot: [14,15] [=====================================>--------] 82% est: 8s 
 plot: [14,16] [=====================================>--------] 82% est: 8s 
 plot: [14,17] [=====================================>--------] 82% est: 8s 
 plot: [15,1] [======================================>--------] 83% est: 8s 
 plot: [15,2] [======================================>--------] 83% est: 8s 
 plot: [15,3] [======================================>--------] 83% est: 7s 
 plot: [15,4] [======================================>--------] 84% est: 7s 
 plot: [15,5] [=======================================>-------] 84% est: 7s 
 plot: [15,6] [=======================================>-------] 84% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,7] [=======================================>-------] 85% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,8] [=======================================>-------] 85% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,9] [=======================================>-------] 85% est: 7s 
 plot: [15,10] [======================================>-------] 86% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,11] [=======================================>------] 86% est: 6s 
 plot: [15,12] [=======================================>------] 87% est: 6s 
 plot: [15,13] [=======================================>------] 87% est: 6s 
 plot: [15,14] [=======================================>------] 87% est: 6s 
 plot: [15,15] [=======================================>------] 88% est: 6s 
 plot: [15,16] [=======================================>------] 88% est: 5s 
 plot: [15,17] [========================================>-----] 88% est: 5s 
 plot: [16,1] [=========================================>-----] 89% est: 5s 
 plot: [16,2] [=========================================>-----] 89% est: 5s 
 plot: [16,3] [=========================================>-----] 89% est: 5s 
 plot: [16,4] [=========================================>-----] 90% est: 5s 
 plot: [16,5] [=========================================>-----] 90% est: 4s 
 plot: [16,6] [=========================================>-----] 90% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,7] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,8] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,9] [==========================================>----] 91% est: 4s 
 plot: [16,10] [=========================================>----] 92% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,11] [=========================================>----] 92% est: 4s 
 plot: [16,12] [=========================================>----] 92% est: 3s 
 plot: [16,13] [==========================================>---] 93% est: 3s 
 plot: [16,14] [==========================================>---] 93% est: 3s 
 plot: [16,15] [==========================================>---] 93% est: 3s 
 plot: [16,16] [==========================================>---] 94% est: 3s 
 plot: [16,17] [==========================================>---] 94% est: 3s 
 plot: [17,1] [===========================================>---] 94% est: 2s 
 plot: [17,2] [============================================>--] 95% est: 2s 
 plot: [17,3] [============================================>--] 95% est: 2s 
 plot: [17,4] [============================================>--] 96% est: 2s 
 plot: [17,5] [============================================>--] 96% est: 2s 
 plot: [17,6] [============================================>--] 96% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,7] [============================================>--] 97% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,8] [=============================================>-] 97% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,9] [=============================================>-] 97% est: 1s 
 plot: [17,10] [============================================>-] 98% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,11] [============================================>-] 98% est: 1s 
 plot: [17,12] [============================================>-] 98% est: 1s 
 plot: [17,13] [============================================>-] 99% est: 1s 
 plot: [17,14] [=============================================>] 99% est: 0s 
 plot: [17,15] [=============================================>] 99% est: 0s 
 plot: [17,16] [=============================================>]100% est: 0s 
 plot: [17,17] [==============================================]100% est: 0s 
                                                                            
ggsave("resid2.png", height = 20, width = 20)

 plot: [1,1] [------------------------------------------------]  0% est: 0s 
 plot: [1,2] [------------------------------------------------]  1% est:13s 
 plot: [1,3] [------------------------------------------------]  1% est:15s 
 plot: [1,4] [>-----------------------------------------------]  1% est:16s 
 plot: [1,5] [>-----------------------------------------------]  2% est:19s 
 plot: [1,6] [>-----------------------------------------------]  2% est:19s 
 plot: [1,7] [>-----------------------------------------------]  2% est:20s 
 plot: [1,8] [>-----------------------------------------------]  3% est:22s 
 plot: [1,9] [>-----------------------------------------------]  3% est:23s 
 plot: [1,10] [=>---------------------------------------------]  3% est:23s 
 plot: [1,11] [=>---------------------------------------------]  4% est:24s 
 plot: [1,12] [=>---------------------------------------------]  4% est:23s 
 plot: [1,13] [=>---------------------------------------------]  4% est:23s 
 plot: [1,14] [=>---------------------------------------------]  5% est:23s 
 plot: [1,15] [=>---------------------------------------------]  5% est:23s 
 plot: [1,16] [==>--------------------------------------------]  6% est:23s 
 plot: [1,17] [==>--------------------------------------------]  6% est:22s 
 plot: [2,1] [==>---------------------------------------------]  6% est:22s 
 plot: [2,2] [==>---------------------------------------------]  7% est:22s 
 plot: [2,3] [==>---------------------------------------------]  7% est:22s 
 plot: [2,4] [==>---------------------------------------------]  7% est:22s 
 plot: [2,5] [===>--------------------------------------------]  8% est:22s 
 plot: [2,6] [===>--------------------------------------------]  8% est:22s 
 plot: [2,7] [===>--------------------------------------------]  8% est:22s 
 plot: [2,8] [===>--------------------------------------------]  9% est:22s 
 plot: [2,9] [===>--------------------------------------------]  9% est:23s 
 plot: [2,10] [===>-------------------------------------------]  9% est:22s 
 plot: [2,11] [====>------------------------------------------] 10% est:23s 
 plot: [2,12] [====>------------------------------------------] 10% est:23s 
 plot: [2,13] [====>------------------------------------------] 10% est:23s 
 plot: [2,14] [====>------------------------------------------] 11% est:22s 
 plot: [2,15] [====>------------------------------------------] 11% est:22s 
 plot: [2,16] [====>------------------------------------------] 11% est:22s 
 plot: [2,17] [=====>-----------------------------------------] 12% est:22s 
 plot: [3,1] [=====>------------------------------------------] 12% est:22s 
 plot: [3,2] [=====>------------------------------------------] 12% est:22s 
 plot: [3,3] [=====>------------------------------------------] 13% est:22s 
 plot: [3,4] [=====>------------------------------------------] 13% est:22s 
 plot: [3,5] [=====>------------------------------------------] 13% est:22s 
 plot: [3,6] [======>-----------------------------------------] 14% est:22s 
 plot: [3,7] [======>-----------------------------------------] 14% est:22s 
 plot: [3,8] [======>-----------------------------------------] 15% est:22s 
 plot: [3,9] [======>-----------------------------------------] 15% est:22s 
 plot: [3,10] [======>----------------------------------------] 15% est:22s 
 plot: [3,11] [======>----------------------------------------] 16% est:22s 
 plot: [3,12] [======>----------------------------------------] 16% est:22s 
 plot: [3,13] [=======>---------------------------------------] 16% est:23s 
 plot: [3,14] [=======>---------------------------------------] 17% est:23s 
 plot: [3,15] [=======>---------------------------------------] 17% est:23s 
 plot: [3,16] [=======>---------------------------------------] 17% est:23s 
 plot: [3,17] [=======>---------------------------------------] 18% est:22s 
 plot: [4,1] [========>---------------------------------------] 18% est:22s 
 plot: [4,2] [========>---------------------------------------] 18% est:22s 
 plot: [4,3] [========>---------------------------------------] 19% est:22s 
 plot: [4,4] [========>---------------------------------------] 19% est:22s 
 plot: [4,5] [========>---------------------------------------] 19% est:22s 
 plot: [4,6] [========>---------------------------------------] 20% est:22s 
 plot: [4,7] [=========>--------------------------------------] 20% est:22s 
 plot: [4,8] [=========>--------------------------------------] 20% est:22s 
 plot: [4,9] [=========>--------------------------------------] 21% est:22s 
 plot: [4,10] [=========>-------------------------------------] 21% est:22s 
 plot: [4,11] [=========>-------------------------------------] 21% est:22s 
 plot: [4,12] [=========>-------------------------------------] 22% est:21s 
 plot: [4,13] [=========>-------------------------------------] 22% est:21s 
 plot: [4,14] [==========>------------------------------------] 22% est:21s 
 plot: [4,15] [==========>------------------------------------] 23% est:21s 
 plot: [4,16] [==========>------------------------------------] 23% est:21s 
 plot: [4,17] [==========>------------------------------------] 24% est:21s 
 plot: [5,1] [==========>-------------------------------------] 24% est:20s 
 plot: [5,2] [===========>------------------------------------] 24% est:20s 
 plot: [5,3] [===========>------------------------------------] 25% est:20s 
 plot: [5,4] [===========>------------------------------------] 25% est:20s 
 plot: [5,5] [===========>------------------------------------] 25% est:20s 
 plot: [5,6] [===========>------------------------------------] 26% est:20s 
 plot: [5,7] [===========>------------------------------------] 26% est:20s 
 plot: [5,8] [============>-----------------------------------] 26% est:20s 
 plot: [5,9] [============>-----------------------------------] 27% est:20s 
 plot: [5,10] [============>----------------------------------] 27% est:20s 
 plot: [5,11] [============>----------------------------------] 27% est:20s 
 plot: [5,12] [============>----------------------------------] 28% est:20s 
 plot: [5,13] [============>----------------------------------] 28% est:20s 
 plot: [5,14] [============>----------------------------------] 28% est:20s 
 plot: [5,15] [============>----------------------------------] 29% est:19s 
 plot: [5,16] [=============>---------------------------------] 29% est:19s 
 plot: [5,17] [=============>---------------------------------] 29% est:19s 
 plot: [6,1] [=============>----------------------------------] 30% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,2] [=============>----------------------------------] 30% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,3] [==============>---------------------------------] 30% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,4] [==============>---------------------------------] 31% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,5] [==============>---------------------------------] 31% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [6,6] [==============>---------------------------------] 31% est:20s 
 plot: [6,7] [==============>---------------------------------] 32% est:20s 
 plot: [6,8] [==============>---------------------------------] 32% est:20s 
 plot: [6,9] [===============>--------------------------------] 33% est:20s 
 plot: [6,10] [==============>--------------------------------] 33% est:20s 
 plot: [6,11] [===============>-------------------------------] 33% est:20s 
 plot: [6,12] [===============>-------------------------------] 34% est:19s 
 plot: [6,13] [===============>-------------------------------] 34% est:19s 
 plot: [6,14] [===============>-------------------------------] 34% est:19s 
 plot: [6,15] [===============>-------------------------------] 35% est:19s 
 plot: [6,16] [===============>-------------------------------] 35% est:19s 
 plot: [6,17] [================>------------------------------] 35% est:19s 
 plot: [7,1] [================>-------------------------------] 36% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,2] [================>-------------------------------] 36% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,3] [================>-------------------------------] 36% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,4] [=================>------------------------------] 37% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,5] [=================>------------------------------] 37% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [7,6] [=================>------------------------------] 37% est:21s 
 plot: [7,7] [=================>------------------------------] 38% est:22s 
 plot: [7,8] [=================>------------------------------] 38% est:21s 
 plot: [7,9] [=================>------------------------------] 38% est:21s 
 plot: [7,10] [=================>-----------------------------] 39% est:21s 
 plot: [7,11] [=================>-----------------------------] 39% est:21s 
 plot: [7,12] [==================>----------------------------] 39% est:21s 
 plot: [7,13] [==================>----------------------------] 40% est:21s 
 plot: [7,14] [==================>----------------------------] 40% est:21s 
 plot: [7,15] [==================>----------------------------] 40% est:21s 
 plot: [7,16] [==================>----------------------------] 41% est:21s 
 plot: [7,17] [==================>----------------------------] 41% est:21s 
 plot: [8,1] [===================>----------------------------] 42% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,2] [===================>----------------------------] 42% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,3] [===================>----------------------------] 42% est:21s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,4] [===================>----------------------------] 43% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,5] [====================>---------------------------] 43% est:22s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [8,6] [====================>---------------------------] 43% est:22s 
 plot: [8,7] [====================>---------------------------] 44% est:22s 
 plot: [8,8] [====================>---------------------------] 44% est:22s 
 plot: [8,9] [====================>---------------------------] 44% est:22s 
 plot: [8,10] [====================>--------------------------] 45% est:22s 
 plot: [8,11] [====================>--------------------------] 45% est:22s 
 plot: [8,12] [====================>--------------------------] 45% est:22s 
 plot: [8,13] [====================>--------------------------] 46% est:22s 
 plot: [8,14] [=====================>-------------------------] 46% est:21s 
 plot: [8,15] [=====================>-------------------------] 46% est:21s 
 plot: [8,16] [=====================>-------------------------] 47% est:21s 
 plot: [8,17] [=====================>-------------------------] 47% est:21s 
 plot: [9,1] [======================>-------------------------] 47% est:21s 
 plot: [9,2] [======================>-------------------------] 48% est:21s 
 plot: [9,3] [======================>-------------------------] 48% est:21s 
 plot: [9,4] [======================>-------------------------] 48% est:20s 
 plot: [9,5] [======================>-------------------------] 49% est:20s 
 plot: [9,6] [=======================>------------------------] 49% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,7] [=======================>------------------------] 49% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,8] [=======================>------------------------] 50% est:20s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [9,9] [=======================>------------------------] 50% est:20s 
 plot: [9,10] [=======================>-----------------------] 51% est:20s 
 plot: [9,11] [=======================>-----------------------] 51% est:20s 
 plot: [9,12] [=======================>-----------------------] 51% est:20s 
 plot: [9,13] [=======================>-----------------------] 52% est:20s 
 plot: [9,14] [=======================>-----------------------] 52% est:19s 
 plot: [9,15] [========================>----------------------] 52% est:19s 
 plot: [9,16] [========================>----------------------] 53% est:19s 
 plot: [9,17] [========================>----------------------] 53% est:19s 
 plot: [10,1] [========================>----------------------] 53% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,2] [========================>----------------------] 54% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,3] [========================>----------------------] 54% est:19s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,4] [=========================>---------------------] 54% est:18s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,5] [=========================>---------------------] 55% est:18s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,6] [=========================>---------------------] 55% est:18s 
 plot: [10,7] [=========================>---------------------] 55% est:18s 
 plot: [10,8] [=========================>---------------------] 56% est:18s 
 plot: [10,9] [=========================>---------------------] 56% est:18s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [10,10] [=========================>--------------------] 56% est:18s 
 plot: [10,11] [=========================>--------------------] 57% est:18s 
 plot: [10,12] [=========================>--------------------] 57% est:18s 
 plot: [10,13] [=========================>--------------------] 57% est:17s 
 plot: [10,14] [==========================>-------------------] 58% est:17s 
 plot: [10,15] [==========================>-------------------] 58% est:17s 
 plot: [10,16] [==========================>-------------------] 58% est:17s 
 plot: [10,17] [==========================>-------------------] 59% est:17s 
 plot: [11,1] [===========================>-------------------] 59% est:17s 
 plot: [11,2] [===========================>-------------------] 60% est:17s 
 plot: [11,3] [===========================>-------------------] 60% est:16s 
 plot: [11,4] [===========================>-------------------] 60% est:16s 
 plot: [11,5] [===========================>-------------------] 61% est:16s 
 plot: [11,6] [============================>------------------] 61% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,7] [============================>------------------] 61% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,8] [============================>------------------] 62% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,9] [============================>------------------] 62% est:16s 
 plot: [11,10] [============================>-----------------] 62% est:16s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [11,11] [============================>-----------------] 63% est:16s 
 plot: [11,12] [============================>-----------------] 63% est:15s 
 plot: [11,13] [============================>-----------------] 63% est:15s 
 plot: [11,14] [============================>-----------------] 64% est:15s 
 plot: [11,15] [============================>-----------------] 64% est:15s 
 plot: [11,16] [=============================>----------------] 64% est:15s 
 plot: [11,17] [=============================>----------------] 65% est:15s 
 plot: [12,1] [==============================>----------------] 65% est:14s 
 plot: [12,2] [==============================>----------------] 65% est:14s 
 plot: [12,3] [==============================>----------------] 66% est:14s 
 plot: [12,4] [==============================>----------------] 66% est:14s 
 plot: [12,5] [==============================>----------------] 66% est:14s 
 plot: [12,6] [==============================>----------------] 67% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,7] [===============================>---------------] 67% est:13s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,8] [===============================>---------------] 67% est:14s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,9] [===============================>---------------] 68% est:14s 
 plot: [12,10] [==============================>---------------] 68% est:13s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [12,11] [===============================>--------------] 69% est:13s 
 plot: [12,12] [===============================>--------------] 69% est:13s 
 plot: [12,13] [===============================>--------------] 69% est:13s 
 plot: [12,14] [===============================>--------------] 70% est:13s 
 plot: [12,15] [===============================>--------------] 70% est:13s 
 plot: [12,16] [===============================>--------------] 70% est:12s 
 plot: [12,17] [===============================>--------------] 71% est:12s 
 plot: [13,1] [================================>--------------] 71% est:12s 
 plot: [13,2] [=================================>-------------] 71% est:12s 
 plot: [13,3] [=================================>-------------] 72% est:12s 
 plot: [13,4] [=================================>-------------] 72% est:12s 
 plot: [13,5] [=================================>-------------] 72% est:11s 
 plot: [13,6] [=================================>-------------] 73% est:11s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,7] [=================================>-------------] 73% est:11s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,8] [=================================>-------------] 73% est:11s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,9] [==================================>------------] 74% est:11s 
 plot: [13,10] [=================================>------------] 74% est:11s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [13,11] [=================================>------------] 74% est:11s 
 plot: [13,12] [=================================>------------] 75% est:11s 
 plot: [13,13] [==================================>-----------] 75% est:11s 
 plot: [13,14] [==================================>-----------] 75% est:10s 
 plot: [13,15] [==================================>-----------] 76% est:10s 
 plot: [13,16] [==================================>-----------] 76% est:10s 
 plot: [13,17] [==================================>-----------] 76% est:10s 
 plot: [14,1] [===================================>-----------] 77% est:10s 
 plot: [14,2] [===================================>-----------] 77% est:10s 
 plot: [14,3] [===================================>-----------] 78% est: 9s 
 plot: [14,4] [====================================>----------] 78% est: 9s 
 plot: [14,5] [====================================>----------] 78% est: 9s 
 plot: [14,6] [====================================>----------] 79% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,7] [====================================>----------] 79% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,8] [====================================>----------] 79% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,9] [====================================>----------] 80% est: 9s 
 plot: [14,10] [====================================>---------] 80% est: 8s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [14,11] [====================================>---------] 80% est: 8s 
 plot: [14,12] [====================================>---------] 81% est: 8s 
 plot: [14,13] [====================================>---------] 81% est: 8s 
 plot: [14,14] [====================================>---------] 81% est: 8s 
 plot: [14,15] [=====================================>--------] 82% est: 8s 
 plot: [14,16] [=====================================>--------] 82% est: 8s 
 plot: [14,17] [=====================================>--------] 82% est: 7s 
 plot: [15,1] [======================================>--------] 83% est: 7s 
 plot: [15,2] [======================================>--------] 83% est: 7s 
 plot: [15,3] [======================================>--------] 83% est: 7s 
 plot: [15,4] [======================================>--------] 84% est: 7s 
 plot: [15,5] [=======================================>-------] 84% est: 7s 
 plot: [15,6] [=======================================>-------] 84% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,7] [=======================================>-------] 85% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,8] [=======================================>-------] 85% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,9] [=======================================>-------] 85% est: 6s 
 plot: [15,10] [======================================>-------] 86% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [15,11] [=======================================>------] 86% est: 6s 
 plot: [15,12] [=======================================>------] 87% est: 6s 
 plot: [15,13] [=======================================>------] 87% est: 6s 
 plot: [15,14] [=======================================>------] 87% est: 5s 
 plot: [15,15] [=======================================>------] 88% est: 5s 
 plot: [15,16] [=======================================>------] 88% est: 5s 
 plot: [15,17] [========================================>-----] 88% est: 5s 
 plot: [16,1] [=========================================>-----] 89% est: 5s 
 plot: [16,2] [=========================================>-----] 89% est: 5s 
 plot: [16,3] [=========================================>-----] 89% est: 5s 
 plot: [16,4] [=========================================>-----] 90% est: 4s 
 plot: [16,5] [=========================================>-----] 90% est: 4s 
 plot: [16,6] [=========================================>-----] 90% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,7] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,8] [==========================================>----] 91% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,9] [==========================================>----] 91% est: 4s 
 plot: [16,10] [=========================================>----] 92% est: 4s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [16,11] [=========================================>----] 92% est: 3s 
 plot: [16,12] [=========================================>----] 92% est: 3s 
 plot: [16,13] [==========================================>---] 93% est: 3s 
 plot: [16,14] [==========================================>---] 93% est: 3s 
 plot: [16,15] [==========================================>---] 93% est: 3s 
 plot: [16,16] [==========================================>---] 94% est: 3s 
 plot: [16,17] [==========================================>---] 94% est: 3s 
 plot: [17,1] [===========================================>---] 94% est: 2s 
 plot: [17,2] [============================================>--] 95% est: 2s 
 plot: [17,3] [============================================>--] 95% est: 2s 
 plot: [17,4] [============================================>--] 96% est: 2s 
 plot: [17,5] [============================================>--] 96% est: 2s 
 plot: [17,6] [============================================>--] 96% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,7] [============================================>--] 97% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,8] [=============================================>-] 97% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,9] [=============================================>-] 97% est: 1s 
 plot: [17,10] [============================================>-] 98% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

 plot: [17,11] [============================================>-] 98% est: 1s 
 plot: [17,12] [============================================>-] 98% est: 1s 
 plot: [17,13] [============================================>-] 99% est: 1s 
 plot: [17,14] [=============================================>] 99% est: 0s 
 plot: [17,15] [=============================================>] 99% est: 0s 
 plot: [17,16] [=============================================>]100% est: 0s 
 plot: [17,17] [==============================================]100% est: 0s 
                                                                            

latitude?

model3a <- lm(price ~ ln_sqft_living + grade + lat,
              data = kc_houses)

summary(model3a)

Call:
lm(formula = price ~ ln_sqft_living + grade + lat, data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1751991  -107963   -23688    66831  5297281 

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -33416813     581524 -57.464  < 2e-16 ***
ln_sqft_living    276165       5462  50.557  < 2e-16 ***
grade3             -1997     261142  -0.008   0.9939    
grade4           -116444     230028  -0.506   0.6127    
grade5           -192182     226678  -0.848   0.3965    
grade6           -218235     226302  -0.964   0.3349    
grade7           -229124     226332  -1.012   0.3114    
grade8           -170011     226403  -0.751   0.4527    
grade9            -24016     226508  -0.106   0.9156    
grade10           206343     226630   0.910   0.3626    
grade11           564131     226890   2.486   0.0129 *  
grade12          1201906     227935   5.273 1.35e-07 ***
grade13          2610142     235325  11.092  < 2e-16 ***
lat               673100      11207  60.060  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 226100 on 21599 degrees of freedom
Multiple R-squared:  0.6209,    Adjusted R-squared:  0.6206 
F-statistic:  2721 on 13 and 21599 DF,  p-value: < 2.2e-16
autoplot(model3a)
Warning: Removed 6866 row(s) containing missing values (geom_path).
Warning: Removed 1 rows containing missing values (geom_point).
Warning: Removed 1 row(s) containing missing values (geom_path).

###add interaction

coplot(resid ~ ln_sqft_living | lat,
        panel = function(x, y, ...){
         points(x, y)
         abline(lm(y ~ x), col = "blue")
       },
       data = price_resid,
       rows = 1)

latitude and ln_sqft_living not worth plotting

ln_sqft_living + grade + lat

price_resid %>% 
  ggplot(aes(x = lat, y = resid, colour = grade))+
  geom_point(alpha = 0.1)+
  geom_smooth(method = "lm", se = FALSE)
`geom_smooth()` using formula 'y ~ x'

lat:grade has potential

price_resid %>% 
  ggplot(aes(x = ln_sqft_living, y = resid, colour = grade))+
  geom_point(alpha = 0.1)+
  geom_smooth(method = "lm", se = FALSE)
`geom_smooth()` using formula 'y ~ x'

best one yet ln_sqft_living:grade

autoplot(model4a)
Warning: Removed 5717 row(s) containing missing values (geom_path).
Warning: Removed 1 rows containing missing values (geom_point).
Warning: Removed 3 row(s) containing missing values (geom_path).

model4b <- lm(price ~ ln_sqft_living + grade + lat +
                lat:grade,
              data = kc_houses)

summary(model4b)

Call:
lm(formula = price ~ ln_sqft_living + grade + lat + lat:grade, 
    data = kc_houses)

Residuals:
     Min       1Q   Median       3Q      Max 
-1614704  -104901   -25936    64782  5271323 

Coefficients: (1 not defined because of singularities)
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    -96315144   45502525  -2.117   0.0343 *  
ln_sqft_living    275323       5434  50.672   <2e-16 ***
grade3          83723487   62949775   1.330   0.1835    
grade4          71133733   49351547   1.441   0.1495    
grade5          74000774   45842975   1.614   0.1065    
grade6          72674921   45538076   1.596   0.1105    
grade7          67029569   45509436   1.473   0.1408    
grade8          60766368   45514094   1.335   0.1819    
grade9          48478822   45533974   1.065   0.2870    
grade10         36661297   45608326   0.804   0.4215    
grade11         38151032   45927619   0.831   0.4062    
grade12        -28417432   47641648  -0.596   0.5509    
grade13          2475898     253927   9.750   <2e-16 ***
lat              1996518     957320   2.086   0.0370 *  
grade3:lat      -1763303    1327013  -1.329   0.1839    
grade4:lat      -1499152    1038414  -1.444   0.1488    
grade5:lat      -1561081     964486  -1.619   0.1056    
grade6:lat      -1533564     958062  -1.601   0.1095    
grade7:lat      -1414981     957459  -1.478   0.1395    
grade8:lat      -1282035     957556  -1.339   0.1806    
grade9:lat      -1020697     957974  -1.065   0.2867    
grade10:lat      -767634     959534  -0.800   0.4237    
grade11:lat      -791515     966230  -0.819   0.4127    
grade12:lat       620491    1002196   0.619   0.5358    
grade13:lat           NA         NA      NA       NA    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 224700 on 21589 degrees of freedom
Multiple R-squared:  0.6257,    Adjusted R-squared:  0.6253 
F-statistic:  1569 on 23 and 21589 DF,  p-value: < 2.2e-16

model4a best

anova(model3a, model4a)
Analysis of Variance Table

Model 1: price ~ ln_sqft_living + grade + lat
Model 2: price ~ ln_sqft_living + grade + lat + ln_sqft_living:grade
  Res.Df        RSS Df  Sum of Sq      F    Pr(>F)    
1  21599 1.1044e+15                                   
2  21589 9.9906e+14 10 1.0534e+14 227.64 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

include as significant at all levels

###relative importance of variables

relaimpo::calc.relimp(model4a, type = "lmg", rela = TRUE)
Response variable: price 
Total response variance: 134782378397 
Analysis based on 21613 observations 

24 Regressors: 
Some regressors combined in groups: 
        Group  grade : grade3 grade4 grade5 grade6 grade7 grade8 grade9 grade10 grade11 grade12 grade13 
        Group  ln_sqft_living:grade : ln_sqft_living:grade3 ln_sqft_living:grade4 ln_sqft_living:grade5 ln_sqft_living:grade6 ln_sqft_living:grade7 ln_sqft_living:grade8 ln_sqft_living:grade9 ln_sqft_living:grade10 ln_sqft_living:grade11 ln_sqft_living:grade12 ln_sqft_living:grade13 

 Relative importance of 4 (groups of) regressors assessed: 
 grade ln_sqft_living:grade ln_sqft_living lat 
 
Proportion of variance explained by model: 65.7%
Metrics are normalized to sum to 100% (rela=TRUE). 

Relative importance metrics: 

                            lmg
grade                0.52139911
ln_sqft_living:grade 0.05523707
ln_sqft_living       0.31354730
lat                  0.10981652

Average coefficients for different model sizes: 

                           1group    2groups      3groups      4groups
ln_sqft_living          528647.45  386004.61    376366.12    499162.04
grade3                   63666.67   35202.77   3604351.43   8833169.25
grade4                   72381.04  -13814.95   1421737.47   2654959.35
grade5                  106523.97  -30045.74   1126368.10   2310960.64
grade6                  159919.64  -13319.69    973091.87   2163168.50
grade7                  260590.26   36082.43    777437.86   1760536.51
grade8                  400852.77  139070.53    407463.76    783882.11
grade9                  631513.19  330866.68   -190030.89   -258079.71
grade10                 929771.07  597898.60  -1518347.22  -3264507.63
grade11                1354841.73  992075.43  -3569200.65  -7892172.22
grade12                2049222.00 1660547.58  -6632106.80 -14390993.21
grade13                3567615.39 3128177.25 -18633828.30 -39350216.24
lat                     813411.58  691928.88    673100.15    670852.62
ln_sqft_living:grade3         NaN        NaN  -1172612.47  -1408594.59
ln_sqft_living:grade4         NaN        NaN   -505355.69   -456944.89
ln_sqft_living:grade5         NaN        NaN   -423302.17   -404437.36
ln_sqft_living:grade6         NaN        NaN   -377388.11   -381812.00
ln_sqft_living:grade7         NaN        NaN   -317029.46   -321161.49
ln_sqft_living:grade8         NaN        NaN   -199757.80   -182409.53
ln_sqft_living:grade9         NaN        NaN    -11515.97    -34118.31
ln_sqft_living:grade10        NaN        NaN    367695.79    358522.69
ln_sqft_living:grade11        NaN        NaN    929266.41    939120.16
ln_sqft_living:grade12        NaN        NaN   1764312.24   1742690.06
ln_sqft_living:grade13        NaN        NaN   4717480.91   4642110.33
LS0tCnRpdGxlOiAiUiBOb3RlYm9vayIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQpgYGB7cn0KbGlicmFyeSh0aWR5dmVyc2UpCmxpYnJhcnkobW9kZWxyKQpsaWJyYXJ5KHNraW1yKQpsaWJyYXJ5KEdHYWxseSkKbGlicmFyeShnZ2ZvcnRpZnkpCmBgYAojIyNjbGVhbmluZyBmb3IgcmVncmVzc2lvbgpgYGB7cn0Ka2NfaG91c2VzIDwtIHJlYWRfY3N2KCJkYXRhL2tjX2hvdXNlX2RhdGEuY3N2IikKYGBgCmBgYHtyfQprY19ob3VzZXMgPC0ga2NfaG91c2VzICU+JQogIHNlbGVjdCgtYyh6aXBjb2RlLCBkYXRlLCBpZCkpICU+JSAKICBtdXRhdGUod2F0ZXJmcm9udCA9IGFzLmxvZ2ljYWwod2F0ZXJmcm9udCksIAogIHlyX3Jlbm92YXRlZCA9IGlmX2Vsc2UoeXJfcmVub3ZhdGVkID4gMCwgVFJVRSwgRkFMU0UpLAogIHZpZXcgPSBhcy5mYWN0b3IodmlldyksCiAgY29uZGl0aW9uID0gYXMuZmFjdG9yKGNvbmRpdGlvbiksCiAgZ3JhZGUgPSBhcy5mYWN0b3IoZ3JhZGUpKQpgYGAKIyMjcmVtb3ZpbmcgYWxpYXNlcwpgYGB7cn0KYWxpYXMobG0ocHJpY2UgfiAuLCBkYXRhID0ga2NfaG91c2VzKSkKCmtjX2hvdXNlcyA8LSBrY19ob3VzZXMgJT4lIAogIHNlbGVjdCgtYyhzcWZ0X2Jhc2VtZW50LCBzcWZ0X2Fib3ZlKSkgCmBgYAoKIyMjY2hvb3NpbmcgZmlyc3QgcHJlZGljdG9yIGZvciBtb2RlbApgYGB7cn0Ka2NfaG91c2VzX251bWVyaWMgPC0gIGtjX2hvdXNlcyAlPiUgCiAgc2VsZWN0X2lmKGlzLm51bWVyaWMpCgprY19ob3VzZXNfbm9uIDwtIGtjX2hvdXNlcyAlPiUgCiAgc2VsZWN0X2lmKGZ1bmN0aW9uKHgpICFpcy5udW1lcmljKHgpKQoKa2NfaG91c2VzX25vbiRwcmljZSA8LSBrY19ob3VzZXMkcHJpY2UKCmdncGFpcnMoa2NfaG91c2VzX251bWVyaWMpCmdnc2F2ZSgibnVtZXJpYy5wbmciLCB3aWR0aCA9IDIwLCBoZWlnaHQgPSAyMCkKZ2dwYWlycyhrY19ob3VzZXNfbm9uKQpnZ3NhdmUoIm5vbm51bWVyaWMucG5nIikKYGBgCndhdGVyZnJvbnQsIHZpZXcgYW5kIGdyYWRlIGhhdmUgcG90ZW50aWFsCnNxZnRfbGl2aW5nLCBzcWZ0X2xpdmluZzE1LCBiYXRocm9vbXMsIGJlZHJvb21zLCBsYXQKCmBgYHtyfQptb2RlbDFhIDwtIGxtKHByaWNlIH4gc3FmdF9saXZpbmcsCiAgICAgICAgICAgICAgZGF0YSA9IGtjX2hvdXNlcykKCmF1dG9wbG90KG1vZGVsMWEpCgpzdW1tYXJ5KG1vZGVsMWEpICN2aW9sYXRlcyBub3JtYWwgZGlzdHJpYnV0aW9uIGFuZCBzY2FsZSBsb2NhdGlvbgpgYGAKYGBge3J9CmtjX2hvdXNlcyA8LSBrY19ob3VzZXMgJT4lIAogIG11dGF0ZShsbl9zcWZ0X2xpdmluZyA9IGxvZyhzcWZ0X2xpdmluZykpCgptb2RlbDFiIDwtIGxtKHByaWNlIH4gbG5fc3FmdF9saXZpbmcsCiAgICAgICAgICAgICAgZGF0YSA9IGtjX2hvdXNlcykKCmF1dG9wbG90KG1vZGVsMWIpCgpzdW1tYXJ5KG1vZGVsMWIpCmBgYApyZWplY3Qgc3FmdF9saXZpbmcgYW5kIGxuX3NxZnRfbGl2aW5nIGJhc2VkIG9uIGRpYWdub3N0aWMgcGxvdHMKCmBgYHtyfQptb2RlbDFjIDwtIGxtKHByaWNlIH4gc3FmdF9saXZpbmcxNSwKICAgICAgICAgICAgICBkYXRhID0ga2NfaG91c2VzKQoKYXV0b3Bsb3QobW9kZWwxYykKCnN1bW1hcnkobW9kZWwxYykKYGBgCmBgYHtyfQprY19ob3VzZXMgPC0ga2NfaG91c2VzICU+JSAKICBtdXRhdGUobG5fc3FmdF9saXZpbmcxNSA9IGxvZyhzcWZ0X2xpdmluZzE1KSkKCm1vZGVsMWQgPC0gbG0ocHJpY2UgfiBsbl9zcWZ0X2xpdmluZzE1LAogICAgICAgICAgICAgIGRhdGEgPSBrY19ob3VzZXMpCgphdXRvcGxvdChtb2RlbDFkKQoKc3VtbWFyeShtb2RlbDFkKQpgYGAKYGBge3J9Cm1vZGVsMWUgPC0gbG0ocHJpY2UgfiBiYXRocm9vbXMsCiAgICAgICAgICAgICAgZGF0YSA9IGtjX2hvdXNlcykKCmF1dG9wbG90KG1vZGVsMWUpCgpzdW1tYXJ5KG1vZGVsMWUpCmBgYApgYGB7cn0KCmtjX2hvdXNlcyA8LSBrY19ob3VzZXMgJT4lIAogIG11dGF0ZShsbl9iYXRocm9vbXMgPSBsb2coMSArIGJhdGhyb29tcykpCgptb2RlbDFmIDwtIGxtKHByaWNlIH4gbG5fYmF0aHJvb21zLAogICAgICAgICAgICAgIGRhdGEgPSBrY19ob3VzZXMpCgphdXRvcGxvdChtb2RlbDFmKQoKc3VtbWFyeShtb2RlbDFmKQoKYGBgCndhdGVyZnJvbnQsIHZpZXcgYW5kIGdyYWRlIGhhdmUgcG90ZW50aWFsCmBgYHtyfQptb2RlbDFnIDwtIGxtKHByaWNlIH4gZ3JhZGUsCiAgICAgICAgICAgICAgZGF0YSA9IGtjX2hvdXNlcykKCmF1dG9wbG90KG1vZGVsMWcpCgpzdW1tYXJ5KG1vZGVsMWcpCmBgYApgYGB7cn0KbW9kZWwxaCA8LSBsbShwcmljZSB+IHZpZXcsCiAgICAgICAgICAgICAgZGF0YSA9IGtjX2hvdXNlcykKCmF1dG9wbG90KG1vZGVsMWgpCgpzdW1tYXJ5KG1vZGVsMWgpCmBgYAptb2RlbDFiIGhhcyB0aGUgaGlnaGVzdCByXjIgYW5kIHRoZSBsZWFzdCBob3JpZmZpYyBkaWFnbm9zdGljIHBsb3RzCgojIyNzZWNvbmQgcHJlZGljb3RyIHRvIGV4cGxhaW4gcmVzaWR1YWxzCmBgYHtyfQpwcmljZV9yZXNpZCA8LSBrY19ob3VzZXMgJT4lIAogIGFkZF9yZXNpZHVhbHMobW9kZWwxYikgJT4lIAogIHNlbGVjdCgtYyhwcmljZSwgZ3JhZGUpKQoKcHJpY2VfcmVzaWQgJT4lIAogIGdncGFpcnMoKQoKZ2dzYXZlKCJyZXNpZC5wbmciLCBoZWlnaHQgPSAyMCwgd2lkdGggPSAyMCkKYGBgCmxhdGl0dWRlCgpgYGB7cn0KbW9kZWwyYSA8LSBsbShwcmljZSB+IGxuX3NxZnRfbGl2aW5nICsgbGF0LAogICAgICAgICAgICAgIGRhdGEgPSBrY19ob3VzZXMpCgphdXRvcGxvdChtb2RlbDJhKQoKc3VtbWFyeShtb2RlbDJhKQpgYGAKCmBgYHtyfQptb2RlbDJiIDwtIGxtKHByaWNlIH4gbG5fc3FmdF9saXZpbmcgKyBncmFkZSwKICAgICAgICAgICAgICBkYXRhID0ga2NfaG91c2VzKQoKYXV0b3Bsb3QobW9kZWwyYikKCnN1bW1hcnkobW9kZWwyYikKYGBgCmBgYHtyfQphbm92YShtb2RlbDFiLCBtb2RlbDJiKQpgYGAKaW5jbHVkZSBhbGwgbGV2ZWxzIGluIG91ciBtb2RlbCBkdWUgdG8gc3RhdGlzdGljYWwgc2lnbmlmaWNhbmNlCjJiIGlzIGNoYW1wISEKCiMjI3RoaXJkIHByZWRpY3RvcgpgYGB7cn0KcHJpY2VfcmVzaWQgPC0ga2NfaG91c2VzICU+JSAKICBhZGRfcmVzaWR1YWxzKG1vZGVsMmIpICU+JSAKICBzZWxlY3QoLWMocHJpY2UsIGxuX3NxZnRfbGl2aW5nLCBncmFkZSkpCgpwcmljZV9yZXNpZCAlPiUgCiAgZ2dwYWlycygpCgpnZ3NhdmUoInJlc2lkMi5wbmciLCBoZWlnaHQgPSAyMCwgd2lkdGggPSAyMCkKYGBgCmxhdGl0dWRlPwoKYGBge3J9Cm1vZGVsM2EgPC0gbG0ocHJpY2UgfiBsbl9zcWZ0X2xpdmluZyArIGdyYWRlICsgbGF0LAogICAgICAgICAgICAgIGRhdGEgPSBrY19ob3VzZXMpCgpzdW1tYXJ5KG1vZGVsM2EpCgphdXRvcGxvdChtb2RlbDNhKQpgYGAKCiMjI2FkZCBpbnRlcmFjdGlvbgpgYGB7cn0KcHJpY2VfcmVzaWQgPC0ga2NfaG91c2VzICU+JSAKICBhZGRfcmVzaWR1YWxzKG1vZGVsM2EpICU+JSAKICBzZWxlY3QoLXByaWNlKQpgYGAKYGBge3J9CmNvcGxvdChyZXNpZCB+IGxuX3NxZnRfbGl2aW5nIHwgbGF0LAogICAgICAgIHBhbmVsID0gZnVuY3Rpb24oeCwgeSwgLi4uKXsKICAgICAgICAgcG9pbnRzKHgsIHkpCiAgICAgICAgIGFibGluZShsbSh5IH4geCksIGNvbCA9ICJibHVlIikKICAgICAgIH0sCiAgICAgICBkYXRhID0gcHJpY2VfcmVzaWQsCiAgICAgICByb3dzID0gMSkKYGBgCmxhdGl0dWRlIGFuZCBsbl9zcWZ0X2xpdmluZyBub3Qgd29ydGggcGxvdHRpbmcKCmxuX3NxZnRfbGl2aW5nICsgZ3JhZGUgKyBsYXQKCmBgYHtyfQpwcmljZV9yZXNpZCAlPiUgCiAgZ2dwbG90KGFlcyh4ID0gbGF0LCB5ID0gcmVzaWQsIGNvbG91ciA9IGdyYWRlKSkrCiAgZ2VvbV9wb2ludChhbHBoYSA9IDAuMSkrCiAgZ2VvbV9zbW9vdGgobWV0aG9kID0gImxtIiwgc2UgPSBGQUxTRSkKYGBgCmxhdDpncmFkZSBoYXMgcG90ZW50aWFsCgpgYGB7cn0KcHJpY2VfcmVzaWQgJT4lIAogIGdncGxvdChhZXMoeCA9IGxuX3NxZnRfbGl2aW5nLCB5ID0gcmVzaWQsIGNvbG91ciA9IGdyYWRlKSkrCiAgZ2VvbV9wb2ludChhbHBoYSA9IDAuMSkrCiAgZ2VvbV9zbW9vdGgobWV0aG9kID0gImxtIiwgc2UgPSBGQUxTRSkKYGBgCmJlc3Qgb25lIHlldCBsbl9zcWZ0X2xpdmluZzpncmFkZQoKYGBge3J9Cm1vZGVsNGEgPC0gbG0ocHJpY2UgfiBsbl9zcWZ0X2xpdmluZyArIGdyYWRlICsgbGF0ICsKICAgICAgICAgICAgICAgIGxuX3NxZnRfbGl2aW5nOmdyYWRlLAogICAgICAgICAgICAgIGRhdGEgPSBrY19ob3VzZXMpCgpzdW1tYXJ5KG1vZGVsNGEpCgphdXRvcGxvdChtb2RlbDRhKQpgYGAKCmBgYHtyfQptb2RlbDRiIDwtIGxtKHByaWNlIH4gbG5fc3FmdF9saXZpbmcgKyBncmFkZSArIGxhdCArCiAgICAgICAgICAgICAgICBsYXQ6Z3JhZGUsCiAgICAgICAgICAgICAgZGF0YSA9IGtjX2hvdXNlcykKCnN1bW1hcnkobW9kZWw0YikKYGBgCm1vZGVsNGEgYmVzdAoKYGBge3J9CmFub3ZhKG1vZGVsM2EsIG1vZGVsNGEpCmBgYAppbmNsdWRlIGFzIHNpZ25pZmljYW50IGF0IGFsbCBsZXZlbHMKCiMjI3JlbGF0aXZlIGltcG9ydGFuY2Ugb2YgdmFyaWFibGVzCmBgYHtyfQpyZWxhaW1wbzo6Y2FsYy5yZWxpbXAobW9kZWw0YSwgdHlwZSA9ICJsbWciLCByZWxhID0gVFJVRSkKYGBgCgoKCgo=